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?