JSON: parse & stringify

Learn the universal language of the web. Discover how to convert JavaScript objects into text for network transmission, and learn which data types get left behind.

JavaScript6 min readConcept 29 of 62

The Universal Data Format

JSON (JavaScript Object Notation) is a lightweight text format used to store and transport data.

Because it is just text, it can be easily sent across the internet and read by almost any programming language, not just JavaScript.

Serialization: The Two Methods

JavaScript provides a global JSON object with two critical methods:

JSON.stringify(data): Converts a live JavaScript object or array into a flat JSON string.

JSON.parse(string): Parses a JSON string back into a live JavaScript object or array.

The Syntax Rules

While JSON looks exactly like a JavaScript object, it has stricter rules:

1. All keys MUST be wrapped in double quotes ("name": "Link").

2. Strings must use double quotes, never single quotes or backticks.

3. No trailing commas are allowed at the end of lists or objects.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1What happens if you use `JSON.stringify()` on an object that has a method (a function) attached to it?
  2. 2Which method turns a JSON string back into a usable JavaScript object?
  3. 3Which of the following is valid JSON syntax?

Remember this

  • JSON is a universal text format for sending data across the network.
  • JSON.stringify() converts JavaScript objects into a text string.
  • JSON.parse() converts a text string back into JavaScript objects.
  • JSON requires double quotes for all keys and strings.
  • Functions, undefined, and Symbols are automatically dropped during stringification.

Done with this concept?

Mark it complete to track your progress. No login needed.