JavaScript .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.
Learn JavaScript on Codecademy
- A full-stack engineer can get a project done from start to finish, back-end to front-end.
- Includes 51 Courses
- With Professional Certification
- Beginner Friendly.150 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours