What counts as valid JSON
JSON is a much smaller language than most people expect. The formal grammar fits on a single page, and it allows exactly six value types: object, array, string, number, boolean, and null. Anything outside that set is a syntax error, no matter how reasonable it looks in JavaScript.
This is the source of most confusion. JSON looks like JavaScript object literal syntax, so developers reach for JavaScript habits that the parser will reject. Knowing the boundary saves a lot of debugging.
- Keys must be double-quoted strings — {name: "ada"} and {'name': 'ada'} are both invalid. Only {"name": "ada"} parses.
- No trailing commas — A comma after the last element of an object or array is a syntax error, even though modern JavaScript allows it.
- No comments — Neither // nor /* */ is permitted. Configuration formats that allow comments, such as JSONC or JSON5, are separate languages.
- No undefined, NaN, or Infinity — These are JavaScript values with no JSON equivalent. JSON.stringify silently drops undefined in objects and converts NaN and Infinity to null.
- Strings use double quotes only — Single-quoted strings are invalid, and literal newlines inside a string must be escaped as \n.