Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local storage and JSON

Where are the data stored in local storage? Is it in form of some text or ASCII format or some other? Is it possible to store JSON data in text files (which can be regularly) updated and retrieve them back? I want to store some JSON data but since my requirement is not so big, I want to abstain from using a database for now.

like image 345
Jack_of_All_Trades Avatar asked Jan 31 '12 13:01

Jack_of_All_Trades


People also ask

What is JSON and local storage?

localStorage An implementation of Client-side Storage. JSON (JavaScript Object Notation) a syntax for serializing objects, arrays, numbers, strings, booleans, and null.

Can local storage store JSON?

Storing JSON, Functions And Arrays in localStorage Luckily, we can store complex data in localStorage by leveraging the JSON object's stringify() and parse() functions. JSON support is quite good on mobile but if you need to add support use json2.

What can be stored in localStorage?

LocalStorage is a key/value datastore that's available on a user's browser. Like cookies, LocalStorage can only store string data for its keys and values. The datastore is only accessible to JavaScript within that domain.


1 Answers

Local storage can only store strings (any data you might have, have to be converted to string upon saving in storage and "revived" upon reading from it).

JSON data is more than fine to be stored as a string so it is good choice of format for keeping complex data in browser storage (either local storage or session storage).

You can learn more about storage here: http://diveintohtml5.info/storage.html

As to where the data is being stored, I imagine it varies from browser to browser but you don't have to worry about where is the data, since you don't have any direct access to it (only through storage API).

Edit: Quick note - I've found this article stating where is storage data stored by Firefox - https://developer.mozilla.org/en/DOM/Storage (see section "Storage location and clearing the data" at the bottom of the page).

like image 159
WTK Avatar answered Oct 09 '22 01:10

WTK