Skip to content

How to read a JSON value

Recognize objects, arrays, and the six kinds of values JSON allows before you try to format a file.

Short answer

JSON is text for data. An object is a set of double-quoted names and values in braces. An array is an ordered list in brackets. Commas sit between items, never after the last one.

The whole grammar is small

A value is an object, an array, a string, a number, true, false, or null. Strings use double quotes. Keys are strings. There are no comments and no trailing commas. A single quote, a bare word, or a function call means you are looking at something that is not JSON, often a JavaScript object someone typed by hand.

Whitespace does not change the value. Formatting only adds line breaks and indentation so people can read it. The formatter on this site parses first. If parsing fails, the text is not JSON yet, and pretty-printing would be a guess.

Practical steps

  1. Find the outer braces or brackets.
  2. Check that every key is in double quotes.
  3. Remove a comma that sits just before } or ].

Common mistakes

  • Treating a JSON string that contains quotes as broken when the quotes are escaped with backslashes.

Frequently asked questions

Can I paste secrets here?
The formatter runs locally in your browser, but you should still avoid pasting passwords into any page.

Related

Sources