Search code snippets, questions, articles...

Convert JSON data to String

You can convert JSON data to a String using JSON.stringify. It can be used to send data to a server in string format if it is in JSON format.
const json_obj = { id: 1, name: "John Rick", pin: "000000" };
const json_str = JSON.stringify(json_obj);

JSON.stringify() method in javascript

You can convert a JSON object or JSON array to string using json.stringify() method. Its takes one required parameter - the JSON object or JSON array that you want to convert to a string.

Basic Syntax:



JSON_OBJECT_OR_ARRAY: The array or object that you want to convert to a string

REPLACER: The keys that you want to take from object - use undefined if you do do not want to take any.

SPACE_SIZE: The space size that you want to use while prettify your json string. If you want to use 3 spaces when prettyfying your string the value of space size will be 3.

Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet