Storing data in a JSON format

Our team requires a service that can periodically generate up-to-date JSON data every 15 minutes for our AJAX services to consume. This JSON will be used for metric analysis and charts among other things.

The reason behind the 15-minute interval is due to the time-consuming nature of the JSON generation process, with queries taking 45-60 seconds to complete. As our application grows, this duration is expected to increase further.

EDIT: All our data is sourced from a SQL database, which is already established as a large relational database setup. Swiftly delivering this data to our web users is essential, hence real-time querying from the database is not feasible due to slow response times.

EDIT 2 The JSON data needs to be completely refreshed every 15 minutes and made readily available. While it's acceptable if the background service takes time to run, ensuring that the JSON is generated on schedule is our priority.

The challenge lies in determining the optimal method to store this growing number of JSON objects - around 30-40 need to be created and serialized for transmission. Additionally, we have predefined time periods for JSON generation: daily, weekly, monthly, quarterly, semiannually, annually, and biennially.

I've contemplated using a flat database table, although I'm hesitant about having tables with numerous columns and only one row. Another option is generating a "data.json" file on the server to pull data from, but are there any potential drawbacks or limitations to this approach? Can it be cached without compromising its purpose?

We're open to exploring alternative storage methods - could an expert provide insights on the best way to handle this scenario?

Answer №1

Instead of generating data dynamically, storing it as text files is the way to go. It's quick, straightforward, and can handle growth with ease. You have the option to create an archive of past information or overwrite old files if they're no longer needed.

To prevent json file caching, you have a couple of options.

$.ajax({ cache: false })

You could also manage caching in the server headers when serving the file. Setting a 15-minute cache time can help reduce strain on your server. The method to implement this depends on the technology you're using.

Answer №2

It seems like you might be relying too heavily on this one example as your primary source of data, possibly overlooking the potential of utilizing APIs from other major companies like Tumblr or Facebook.

However, I want to emphasize that using a database to store your data would offer greater efficiency compared to storing it in JSON format.

If you opt to store data in a file, you'll need to develop your own plugins to manage and validate the data within the file, ensuring its accuracy and relevance. This could be quite time-consuming in terms of coding. On the contrary, databases allow you to effortlessly select specific rows and columns, convert that data into JSON format, and then deliver it back to the client as a JSON object - which is likely your desired outcome.

By utilizing a database, you can create a table for each distinct JSON object you plan to use, similar to the following:

ObjId | ObjName | ObjProperty
1     | User    | Employee
2     | User    | Client

This serves as an illustrative table layout. After successfully storing the data, retrieving it simply involves executing a SELECT statement like so:

SELECT * FROM table_name WHERE ObjId = 1

Upon execution, the first row will be returned. You can then stringify it and send it as a string to the client for further processing.

Visit this link for additional information on converting objects to strings using JSON.stringify

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CORS (Cross-Origin Resource Sharing) Request Failed

Whenever I utilize axios to send a XMLHttpRequest, an error occurs. Error: XMLHttpRequest cannot load . The preflight request is unsuccessful because there is no 'Access-Control-Allow-Origin' header present on the requested resource. Hence, acce ...

JQuery is displaying the word "undefined" instead of the expected JSON array values

Currently, I'm in the process of developing a PhoneGap application that utilizes JQuery and AJAX to interact with JSON data from a PHP file. Specifically, there's a part of my app where I want users to click a button and have it display a list of ...

After the form is submitted, attach a div containing the saved record

Once the form is submitted, I'd like to seamlessly add the newly saved record to my existing div that holds all the records. If there's a better method for accomplishing this, please let me know. I'm unsure of the correct approach to achiev ...

Guide to sending both JSON data and form data in a single request using Laravel 9

I am working on a form where I need to input multiple images that will be converted into JSON format. The HTML for my form: create.blade.php <form method="post" action="{{ route('m_announcement.store') }}" enctype="mu ...

The next.js Head component that is imported from next/head is not functioning correctly when used on share pages

I recently switched my website from create-react-app to create-next-app, but I'm having issues with the Head(app/head) component. Let's say I have a blog section with pages structured as follows: pages/blog/index.js and pages/blog/[slug].js. In ...

What is causing the scripts to fail when I attempt to press a button?

Clicking on the button is supposed to slowly reveal phone numbers on the page. Here are the HTML Codes: <span id="show-phone-numbers" class="btn btn-success"> <i class="fe fe-phone-call"></i> Show Phone Nu ...

Tips for interpreting JSON information and showcasing it with the assistance of Ajax in JQuery?

There's a request made to the system via AJAX that returns JSON as a response, which is then displayed in an HTML table. The HTML code for displaying the data looks like this: <table id="documentDisplay"> <thead> <tr ...

Storybook encounters an undefined error with the Vuex store

Here is a snippet from my main.js file: import './plugins'; import store from './store'; import FileUpload from './components/FileUpload'; export default { install(Vue) { Vue.component('file-upload', ...

The embedded iframe on YouTube is displaying the incorrect video

I am currently designing a website and I want to feature a video on the homepage. The video is hosted on YouTube and I need to embed it into my website. <html> <iframe width="560" height="315" src="https://www.youtube.com/embed/spPdelVEs_k?rel= ...

What could be the reason that data-bs-placement="right" is not functioning as expected?

I am facing an issue with the popover functionality in my project. No matter what value I set for data-bs-placement attribute, it does not display correctly. Can you help me understand why this is happening? <!DOCTYPE html> <html lang="en ...

Exploring the differences between UTC and non-UTC date formats in Javascript

When working with JavaScript, I encountered a challenge in comparing two dates that are formatted differently. Specifically: 2015-09-30T00:00:00 and 9/30/2015 12:00:00 AM The former is in UTC format while the latter is not. Despite referring to the same ...

Saving changes made in HTML is not supported when a checkbox is selected and the page is navigated in a React application using Bootstrap

In my array, there are multiple "question" elements with a similar structure like this: <><div className="row"><div className="col-12 col-md-9 col-lg-10 col-xl-10 col-xxl-10"><span>Question 1</span></div ...

What is the best way to save my output in a JSON format file?

As I embark on this new journey, I find myself faced with a file containing 50,000 tweets in JSON format. My goal is to convert these tweets into a more readable format. I attempted to implement the following code, but I am unsure how to save the output to ...

What is the best way to create a taskbar using HTML or Javascript?

I'm currently developing an innovative online operating system and I am in need of a functional taskbar for user convenience. The ideal taskbar would resemble the Windows taskbar, located at the bottom of the screen with various applications easily ac ...

Activating events with Jquery

Can anyone help me with this HTML and jQuery issue I'm facing? When I click on an image for the first time (when it has the class 'hide'), the first jQuery click function is executed. However, when I click on the image again, the second func ...

Another option for authorizing a document

DISCLAIMER: I am seeking information on technologies for signing a JSON document from the server-side, not recommendations for specific products or services. I want to explore the various options available for signing a JSON document, especially when mult ...

Issue with Chrome not triggering onMouseEnter event when an element blocking the cursor disappears in React

Important Note: This issue seems to be specific to Chrome Currently, React does not trigger the onMouseEnter event when a blocking element disappears. This behavior is different from standard JavaScript events and even delegated events. Below is a simpli ...

Error message encountered when submitting a form after receiving an AJAX response: VerifyCsrfToken Exception

I'm encountering an issue with my AJAX functionality that involves rendering a form with multiple input fields and a submit button. Here is the AJAX call: <script type="text/javascript"> $('#call_filter').click(function() { $.aja ...

Why is the Axios instance/function not being passed the argument?

I am currently working on refactoring a next.js App that has a functioning axios call. However, I have encountered an issue with my new function not receiving arguments. The problem consists of two main components: my next.js page and an external custom m ...

"Using jQuery's Ajax feature to efficiently delete a record

I am currently facing an issue with deleting a value from a comma-separated string in a table. The script responsible for deletion (delete_url.php) functions correctly when I manually set the post values, however, I am encountering difficulty in passing th ...