.stringify()
Published Jun 2, 2022
Contribute to Docs
The .stringify()
method returns a string representation of a given JSON object. It is one of two methods that belong to the reserved JSON
object, the other being the .parse()
method.
Syntax
JSON.stringify(jsonObject);
The jsonObject
must be valid. Otherwise, a SyntaxError
is thrown.
Example
In the example below, a valid JSON object is stored in a variable, myJSONObject
, and then passed into the .stringify()
method as an argument:
let myJSONObject = {Hello: 'World',};console.log(JSON.stringify(myJSONObject));
The output will look like this:
{"Hello":"World"}
Codebyte Example
The following example further demonstrates how the .stringify()
method works:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.