Skip to content
dreamcode
dreamcode
Map
JSON
Lesson 23 of 48
+15 XP on finish
JS COLLECTIONSChapter 4 · JS Collections Depth

JSON

JSON is how data travels between programs and across the web. JSON.stringify(value) turns an object or array into JSON text, and JSON.parse(text) turns JSON text back into a value. Pass extra arguments like JSON.stringify(data, null, 2) for readable, indented output. Functions and undefined values are left out of the text.

Worked example

How it reads

  • stringify produces text with double-quoted keys
  • parse gives you a normal object you can read with dots
  • undefined properties disappear from the JSON
Cloud tip: JSON.parse throws on invalid text. Wrap it in try...catch when the text comes from outside your program.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Parse raw with JSON.parse and print just the hours: 42.

Press Run to check your work.