Storing JSON data in browser memory

SharpCoder picture SharpCoder · Sep 20, 2013 · Viewed 13.3k times · Source

I want to persist some JSON information in browser. Depending on user interaction with the application, I want to store 5-6 different JSON object into memory. What options I have to achieve this? Please suggest any library or plugin using which I can persist information in the browser.

Thanks

Answer

Rupam Datta picture Rupam Datta · Apr 1, 2015

To add to the solutions given, I'd also want to add a reference link Storing Objects in HTML5 localStorage where this question is discussed nicely.

Below is the code

var testObject = { 'one': 1, 'two': 2, 'three': 3 };

// Put the object into storage
localStorage.setItem('testObject', JSON.stringify(testObject));

// Retrieve the object from storage
var retrievedObject = localStorage.getItem('testObject');

console.log('retrievedObject: ', JSON.parse(retrievedObject));

Courtesy: CMS