Skip to content

Convert a JSON object to a string

In several use cases, for example working with HTML5 localStorage, we can’t operate using JSON objects directly. Instead, you have to convert the object to a string when putting it into and from a string to an object when taking it out.

To convert the object to a string, using native JavaScript, you can use the JSON.stringify() function:

var obj = {'firstName': 'John', 'lastName': 'Doe'};
json = JSON.stringify(obj);


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.