What is the most effective method for utilizing JSON as a database?

For my upcoming offline mobile web app project, I am considering using JSON to mirror some of my database tables and storing the data in localStorage. (Although Web SQL Database is an option, its future-proofing capabilities are questionable.)

Initially, I generated a basic JSON output from the database that looked something like this:

{
  "1": {"id":"1","name":"Hello","alias":"hello","category":"8"},
  "2": {"id":"2","name":"World","alias":"world","category":"3"},
  ...
}

However, with numerous tables containing significant amounts of data, I realized that there could be storage issues due to repetitive field names. By modifying the format to store data as arrays, the size was reduced by half:

{
  "1": ["1","Hello","hello","8"},
  "2": ["2","World","world","3"},
  ...
}

Nevertheless, this new structure requires referencing data using numerical indexes, which may result in cluttered code filled with seemingly arbitrary numbers. One solution I considered was storing an array such as ["id","name"...] in a separate variable, but the additional lookups seemed prone to complications.

Are there any practical methods to streamline this process while maintaining clean Javascript code? Additionally, are there other effective strategies for handling this type of development?

Answer №1

Is it feasible to transform the data into a structure similar to the following:

{
   id:{1:1, 2:2, ...},
   name:{1:hello, 2:world},
   alias:{1:hello, 2:world},
   category{1:8, 2:3}
}

By organizing the data in this way, each column is stored only once while still allowing for easy retrieval based on id.

Answer №2

It's important to remember that JSON is not a database - it's actually a format used for exchanging data between systems.

Answer №3

It's uncertain if the functionality would be consistent on various mobile operating systems, however using XML could be a potential solution.

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

Filtering arrays using jq at a nested level

I have noticed that all the demo/examples I've come across are filtering on the first level, but my requirement is to perform array filtering with jq on the second level: { "TheArray": [ { "F1": "V11", "F2": "V12", "F3": "V13" ...

Missing sidebar display

Hi there! I am having an issue with my sidebar not appearing correctly when I click on the toggle button. It seems to be moving to the side, but the sidebar itself is blank or transparent. I suspect that the problem lies within my JavaScript file. As a beg ...

Finding the best way to transfer text between DIV elements?

I have a dilemma involving two DIV elements positioned absolutely on the sides of an HTML page, much like this EXAMPLE: <div class="left"> </div> <div class="right"> </div> These are styled using the following CSS: .left{ pos ...

Executing JavaScript code from an external link

Currently, I am in the process of developing a horizontal parallax website. The functionality is working seamlessly; when I click on the menu, the slides smoothly transition horizontally and display the corresponding content. However, I have encountered a ...

jQuery Mishap - Creating an Unspecified Issue

At the moment, my website displays a list of registered users in one column and their email addresses with checkboxes next to them in another column. Users can check the boxes and then click a submit button to generate a list of the selected emails separat ...

Performing a $.POST request on a Squarespace webpage

I created a custom form on my website for booking appointments, and it posts to a third-party server. When I submit the form using the <form> tag, I receive the email notification. However, I want to submit the form using $.POST so that I can customi ...

Sorting functionality malfunctioning after dynamically adding new content using AJAX

Greetings to all, I have a question about my views. 1- Index 2- Edit In the index view, I have a button and AJAX functionality. When I click the button, it passes an ID to the controller which returns a view that I then append to a div. The Edit view con ...

Unable to access $_SESSION variable when making AJAX request from a different port

After creating a website with PHP on port 80 (index.php) and setting the session variable with the userid upon login, I encountered an issue when clicking on a link that redirected me to port 8080, which is where a JavaScript file containing node.js proces ...

Utilizing nodejs to interact with a web service

Recently diving into Node.js and currently exploring how to utilize services with NodeJS. Seeking guidance on the NodeJS equivalent of the code snippet provided below: $.ajax({ type: "POST", url: "/WebServiceUtility.aspx/CustomOrderService", data: " ...

Searching in Vue based on the selected option is only possible by the selected criteria and not by id, regardless of the

#1 Even if chosen, cannot search by id. The 'name' condition in the loop works well but I am unable to correctly search by id (returns nothing). #2 When selecting an option from the dropdown menu, it only displays until I start typing. I would l ...

How can I obtain a JSONObject as a response in REST Client?

I am currently following a tutorial at https://github.com/excilys/androidannotations/wiki/Rest%20API and I'm looking to bypass the JSON to POJO conversion process and instead work with pure JSONObject (or gson's JsonObject). What should I include ...

Why isn't my Bootstrap dropdown displaying any options?

I am new to web development and attempting to create a button that triggers a dropdown menu when clicked. I have tried the following code, but for some reason, the dropdown is not working correctly. Can anyone help me identify the issue or correct my code? ...

Angular.js: Ensure all services are loaded before initializing the application

I am currently developing an application using angular.js and I need to ensure that the result from a specific service is accessible throughout the entire application right from the beginning. How can this be accomplished? The service in question is as f ...

Tips for effectively managing dynamic xpaths

When conducting a search operation, I am required to select the text that is returned as a result. Each search will produce different xpaths. Below are examples of various xpaths returned during a search: .//*[@id='messageBoxForm']/div/div[1]/di ...

Bug Alert: Incompatibility between Angular $resource and PHP causing issues with Update and Delete functionalities

As a newcomer to both AngularJS and PHP, I have been struggling to find comprehensive documentation on using $resource to update records in a database. While I did come across a helpful tutorial here that covers most aspects of $resource usage, I am having ...

A collaborative effort on Facebook, Twitter, and GooglePlus involves generating SCRIPT tags collectively

If you're familiar with the javascripts used by platforms like Facebook, Twitter, and Google Plus, you'll recognize them below. Here, I've simply organized them neatly together. How can I utilize jQuery to create the script tags and optimiz ...

Discover the syntax for reading route parameters in Angular

Currently, I am integrating the Paypal API into my project. After confirming a purchase, Paypal redirects to a specified URL. I set the desired URL as "localhost:4200/shop/order". However, when Paypal returns the URL, it appends the token and payerid at th ...

What is the best way to transform XML.gz files into JSON format?

I have recently started working with XML and I am trying to send a GET request to an endpoint to retrieve some data. The response I am getting back is in xml.gz format, but I would like to convert it to JSON on my node server. Is there a way for me to acco ...

Converting JSON data to a data frame in R

I'm currently facing an issue with using the rjson package in converting JSON to an R data.frame. My initial attempt looks like this: library("rjson") json_file <- "btcusd.txt" json_data <- fromJSON(paste(readLines(json_file), collapse="")) T ...

`When you extend a $resource object, it effectively removes the prototype from the

Here's the current code snippet I'm working with: // Factory angular.factory('Student', function() { var defaults = { StudentId: null }; var Student = function(params) { angular.extend(this, angular.copy(de ...