JSON playground
Type JSON and see if it is valid, what it describes, how JavaScript reaches each value, and what the mistake is.
JSON is a way of writing data as text. It uses the same square brackets for arrays and curly brackets for objects that you know from JavaScript, but it is stricter: names and text need double quotes, and there is no comma after the last item.
JSON.parse turns JSON text into an array or object you can use, and JSON.stringify turns it back into text. If the text is not valid JSON, JSON.parse stops with an error.
Things to try
- Click each sample. Which ones are valid, and what does the green line say each one is?
- Change the age of the pet to 4 and watch the table. What would data.age give in JavaScript?
- Delete the last closing bracket. What does the error say?
- Add a new property with a comma before it, like "color": "grey".