JSON Cheat Sheet

The rules of JSON on one page, plus what every common JSON.parse error actually means and how to fix it.

Cheat sheetPrintableFree, no login

Updated 28 October 2026

Format, validate and fix JSON — it points to the exact line and column of an error.

Open the JSON formatter

Data types

TypeExampleNotes
String"hello"Double quotes only. Single quotes are not JSON.
Number42 -3.14 1e6No leading zeros, no NaN or Infinity, no hex.
Booleantrue falseLowercase only.
NullnullLowercase. There is no undefined.
Object{"name": "Alice", "age": 30}Keys must be double-quoted strings.
Array[1, "two", true, null]Values can be mixed types.

Syntax rules

Escape sequences

EscapeMeans
\"Double quote
\\Backslash
\/Forward slash (optional)
\nNew line
\rCarriage return
\tTab
\b \fBackspace, form feed
\u00e9Unicode character by code point (é)

Raw tabs and line breaks inside a string are not allowed — they must be written as \t and \n. Windows paths need doubled backslashes: "C:\\Users\\alice".

Common JSON errors and how to fix them

Error message (Chrome, Edge, Node.js)ExampleCauseFix
Expected double-quoted property name{"a": 1,}A trailing comma after the last property, or a single-quoted keyRemove the comma; use double quotesTry ↗
Expected property name or '}'{'a': 1}Key in single quotes or without quotesWrite keys as "a"Try ↗
Unexpected token ']', "[1, 2,]" is not valid JSON[1, 2,]A trailing comma in an arrayRemove the last commaTry ↗
Expected ',' or '}' after property value{"a": 1 "b": 2}A missing comma, or a // comment after a valueAdd the comma; remove commentsTry ↗
Expected ',' or ']' after array element{"a": [1, 2Unclosed array or truncated JSONClose every [ and {Try ↗
Unexpected end of JSON inputemptyEmpty string, or the response was cut offCheck that the request returned a body
"undefined" is not valid JSONundefinedYou parsed the JavaScript value undefinedCheck the variable before JSON.parseTry ↗
Unexpected token '<', "<!DOCTYPE "... is not valid JSON<!DOCTYPE html>The server sent an HTML page (often a 404 or login page), not JSONCheck the URL and the response statusTry ↗
Unexpected token 'N', … is not valid JSON{"a": NaN}NaN or Infinity, which JSON doesn't supportUse null or a stringTry ↗
Bad control character in string literal{"a": "line1 line2"}A raw line break or tab inside a stringEscape it as \n or \tTry ↗
Bad escaped character{"path": "C:\Users"}A single backslash before a letter that isn't an escapeDouble the backslash: \\Try ↗
Unexpected non-whitespace character after JSON{"a":1}{"b":2}Two JSON documents, or extra text after the endWrap them in an array, or use JSON LinesTry ↗

Firefox words these differently, for example JSON.parse: expected double-quoted property name at line 1 column 9. Try ↗ opens the broken example in the JSON formatter, which points to the line and column and can fix the common cases in one click.

Parse and write JSON in code

LanguageParseWrite (pretty)
JavaScriptJSON.parse(text)JSON.stringify(obj, null, 2)
Pythonjson.loads(text)json.dumps(obj, indent=2)
Gojson.Unmarshal(data, &v)json.MarshalIndent(v, "", " ")
Java (Jackson)mapper.readValue(text, User.class)mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj)
C# (.NET)JsonSerializer.Deserialize<User>(text)JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true })
PHPjson_decode($text, true)json_encode($v, JSON_PRETTY_PRINT)
Command line (jq)jq '.users[0].name' file.jsonjq . file.json (pretty), jq -c . file.json (minify)

JSON vs JSONC vs JSON5 vs JSON Lines

FormatWhat's differentUsed for
JSONThe strict standard (RFC 8259)APIs, data exchange
JSONCJSON plus // and /* */ commentstsconfig.json, VS Code settings
JSON5Comments, trailing commas, single quotes, unquoted keys, hex numbersHand-edited config files
JSON Lines (NDJSON)One JSON value per line, no wrapping arrayLogs, streaming, big data exports
JSON SchemaA JSON document that describes the shape of other JSONValidation, API docs

Frequently asked questions

Does JSON allow comments?
No. Standard JSON has no comments. Formats like JSONC (used by VS Code and tsconfig.json) and JSON5 add them, but a strict JSON parser such as JSON.parse will reject them.
Does JSON allow trailing commas?
No. [1, 2,] and {"a": 1,} are invalid JSON. Remove the comma after the last item.
Can JSON use single quotes?
No. Strings and keys must use double quotes. Single quotes are a JavaScript and Python habit, not JSON.
What does "Unexpected token < in JSON at position 0" mean?
Your code tried to parse an HTML page as JSON — usually a 404, 500 or login page returned by the server. Check the request URL and the response status. Newer Chrome words it as Unexpected token '<', "<!DOCTYPE "... is not valid JSON.
How do I store a date in JSON?
As a string in ISO 8601 format, for example "2026-10-28T09:30:00Z". JSON has no date type.
✓ Copied!