JSON6 Troubleshooting Guides
Find the cause of a JSON6 parse error, or a document that loads wrong without any error.
Start here: Look up the exact message in the error reference, or read Fixing Parse Errors for the common mistakes. The dangerous problems are the ones that do not throw.
Troubleshooting Guides
Two pages cover what goes wrong when you read JSON6. One teaches the habits; the other is the lookup table.
Find the Fix by Symptom
Match what you are seeing to the entry in the error reference. Messages are quoted exactly as json-6 1.1.7 prints them.
| What you see | Most likely cause | Go to |
|---|---|---|
No value found in document | Empty file, or a { / [ that was never closed | No value found |
Incomplete string | A quote was never closed; the string ran to the end of the file | Incomplete string |
fault parsing 'x' unexpected | Missing comma, bare-word value, or a stray character | fault parsing |
Two values with no separator | Missing comma between array items or literals | Two values |
bad context; excessive commas | A doubled comma in an object, or a comma after a bare key | Excessive commas |
Object field name with no value | A key with no colon and value | Field name with no value |
Fault while parsing; unexpected '}' | A closing brace that does not match the open bracket | Unexpected close |
fault while parsing number; | Letters, a second decimal point or a semicolon after digits | Number faults |
(escaped character, parsing hex of \u) | A backslash in a string, often a Windows path | Escape digits |
Legacy octal / leading-zero numbers are not allowed | Strict mode is on and a number starts with 0 | Strict leading zero |
context stack is not empty at flush | A streaming parser was flushed while reading a number inside an open object or array | Stream flush |
Behaviors That Surprise People
These do not produce an error message at all, which is why they cause the longest debugging sessions. Each was reproduced with json-6 1.1.7.
- Text after the first value is ignored.
JSON6.parse('{ a: 1 } x')returns{ a: 1 }. A stray}in the middle of a file silently drops everything after it. How to require exactly one value. - Leading zeros are decimal.
0123is 123 in JSON6, but a JavaScript engine in sloppy mode reads it as octal 83. Copying such a value into code changes its meaning. See numbers. - The
__proto__key changes the prototype.JSON6.parse('{"__proto__": {"x": 1}}')returns an object that inheritsx. JSON.parse and JSON5 create an ordinary property instead. Config loaders should check the prototype of what they parse. - The error class is Error. Code that catches
SyntaxErrorto detect a bad document will not see json-6 failures. stringify()does not produce JSON. Keys that are valid identifiers come out unquoted, keys are sorted alphabetically by default, and newlines inside strings are emitted raw. ADatebecomes{}, andundefinedstays in arrays instead of becomingnull. UseJSON.stringifywhen the output must be read by something that expects JSON. The JSON5 migration guide has the full comparison.- Backslashes are escapes.
'C:\temp'contains a tab. Double the backslashes or use forward slashes.
Getting Help
If a document fails and the reference does not explain why, reduce it to the smallest input that still fails and run it through the online validator. Bugs in the parser itself belong on the project's GitHub issue tracker, where the library's README says feature requests and bug reports are handled. Questions about this site go through the contact page.
JSON6 has a small ecosystem, and few third-party tools understand the .json6 extension. If an editor or build tool reports a syntax error on a file that the json-6 parser accepts, the tool is almost certainly parsing it as plain JSON. The editors guide lists what works.
FAQ
Where do I look first when a .json6 file will not load?
Read the line and column at the end of the error message, then check the character before it. Missing commas are reported at the next key. If the message is "No value found in document", check the end of the file for an unclosed bracket.
Does the error tell me the file name?
No. The parser receives only text. Add the file name yourself when you catch the error, as the config loader tutorial does.
Check a Document Now
The validator runs the json-6 parser in your browser and shows the exact message and position.