JSON6 Error Messages
Every error the json-6 parser can throw, with the real message, the cause and the fix.
In short: Errors are plain Error objects whose message ends in [line:col]. This page lists every message in json-6 1.1.7, each produced by running the code, with a permanent anchor you can link to.
How to Read a JSON6 Error
Every JSON6 parse failure is a plain JavaScript Error. It is not a SyntaxError, so err instanceof SyntaxError is false, and it has no line or column property. The position is only in the message text. Match on the message, not the class, and read the line and column from the trailing [line:col].
Most messages share one shape. Here is a real one, produced by a missing comma:
const JSON6 = require('json-6'); try { JSON6.parse('{a:1 b:2}'); } catch (err) { console.log(err.name); // Error console.log(err.message); }Error fault parsing 'b' unexpected at 6 (near ':1 [b]:2}') [1:6]| Part | Meaning |
|---|---|
fault parsing | The leader: what the parser was doing or what rule was broken. This is the part this page indexes. Some leaders already contain the word "unexpected", so you may see it twice. |
'b' | The offending character. Absent for errors found at the end of the input. |
at 6 | One-based character offset into the text, counted in UTF-16 code units from the start. |
(near ':1 [b]:2}') | Up to three characters before the problem, the problem character in square brackets, then up to ten characters after. A newline is printed as a raw newline, so some messages span two lines. |
[1:6] | Line 1, column 6, both one-based. Use this to jump to the spot in an editor. |
The parser reports the first character it cannot accept, which is often one token after the real mistake. For a missing comma, the error points at the start of the next key. Always look at the character before the position too.
Truncated and trailing input behave differently from JSON.parse. JSON6.parse('{a:1') reports "No value found in document", and JSON6.parse('{a:1} x') succeeds and returns { a: 1 }: text after the first complete value is ignored. See what does not throw and the strict loader in the config files tutorial.
Whole-Document Errors
These fire when the parser reaches the end of the text and something is still open or missing.
No value found in document
Triggered by:
(an empty file)Error: No value found in document{a:1Error: No value found in document[[1]Error: No value found in documentCause. The text contained no complete value. Either it is empty, whitespace only, or comments only, or a { or [ was opened and never closed. The second case is the surprising one: an unclosed container does not say "unterminated object", it says there is no value at all.
Fix. Check the end of the file for a missing } or ] (a bracket matcher in your editor finds it fast). If the file is meant to be empty, handle that before calling parse().
Comment began at end of document
Triggered by:
/Error: Comment began at end of document at 1 [1:1]Cause. The text ends with a single /. The parser saw the start of a comment and then ran out of input.
Fix. Remove the stray slash, or finish the comment with // or /* ... */.
Open comment '/*' is missing close at end of document
Triggered by:
/* abcError: Open comment '/*' is missing close at end of document at 6 [1:6]Cause. A block comment was opened and the file ended before */. Everything after the /* was treated as comment text.
Fix. Add the closing */. If you meant a line comment, use //, which needs no terminator.
Incomplete '/* *' close at end of document
Triggered by:
/* abc *Error: Incomplete '/* *' close at end of document at 8 [1:8]Cause. The text ends with * where the closing */ should be. The slash is missing.
Fix. Append the /.
Incomplete string
Triggered by:
{a:"xError: Incomplete string at 5 [1:5]{a:'x}Error: Incomplete string at 6 [1:6]Cause. A string was opened with ", ' or a back-tick and the text ended before the matching quote. Because JSON6 strings may span lines, a missing quote does not stop at the end of the line the way it does in JSON: the string swallows the rest of the file.
Fix. Close the string with the same quote character that opened it. The position in the message points at the end of the input, not at the opening quote, so search backwards for the quote that has no partner.
Structure Errors
These mean the punctuation between members is wrong: a missing or doubled comma, a stray bracket, a key with no value.
fault parsing '<char>' unexpected
Triggered by:
{a:1 b:2}Error: fault parsing 'b' unexpected at 6 (near ':1 [b]:2}') [1:6]{a:1 b}Error: fault parsing 'b' unexpected at 6 (near ':1 [b]}') [1:6][a:1]Error: fault parsing 'a' unexpected at 2 (near '[[a]:1]') [1:2]@Error: fault parsing '@' unexpected at 1 (near '[@]') [1:1]Cause. The catch-all. The parser met a character that cannot start or continue anything at that point. By far the most common cause is a missing comma between two members, which makes the next key look like a stray word. Bare words that are not keywords ({a:b}), a : inside an array, and characters such as @ or # land here too.
Fix. Look at the character in brackets inside near and the one just before it. Add the missing comma, quote the value if it is a string, or delete the stray character.
Two values with no separator between them
Triggered by:
[1 2]Error: Two values with no separator between them '2' unexpected at 4 (near '[1 [2]]') [1:4]{a:true false}Error: Two values with no separator between them 'f' unexpected at 9 (near 'ue [f]alse}') [1:9]Cause. Two literals appeared in a row with only whitespace between them: numbers, or true, false, null.
Fix. Insert the comma. Note that [1 /* c */ 2] fails the same way, because a comment is not a separator.
String unexpected
Triggered by:
[1 "y"]Error: String unexpected '"' unexpected at 4 (near '[1 ["]y"]') [1:4]{a:1 "y"}Error: String unexpected '"' unexpected at 6 (near ':1 ["]y"}') [1:6]Cause. A string started where a value was already complete, again usually a missing comma.
Fix. Add the comma before the string.
String begin after previous value
Triggered by:
{"a" "b":1}Error: String begin after previous value '"' unexpected at 6 (near 'a" ["]b":1}') [1:6]Cause. Inside an object, two key strings appeared back to back, so the first key never got its : and value.
Fix. Complete the first member ("a": 1,) or remove the extra key.
bad context; excessive commas while parsing;
Triggered by:
{a:1,,b:2}Error: bad context; excessive commas while parsing; ',' unexpected at 6 (near ':1,[,]b:2}') [1:6]{,}Error: bad context; excessive commas while parsing; ',' unexpected at 2 (near '{[,]}') [1:2]{a,}Error: bad context; excessive commas while parsing; ',' unexpected at 3 (near '{a[,]}') [1:3],Error: bad context; excessive commas while parsing; ',' unexpected at 1 (near '[,]') [1:1]Cause. A comma in a place that has no empty slot. Arrays tolerate doubled commas (they create empty members), but objects do not, and a comma at the very top level is meaningless. A comma straight after a bare key ({a,}) also lands here.
Fix. Delete the extra comma. In an array, remember that [1,,2] is legal and has three slots, with the middle one empty.
Unexpected comma after object field name
Triggered by:
{a:,}Error: Unexpected comma after object field name ',' unexpected at 4 (near '{a:[,]}') [1:4]{a:,b:1}Error: Unexpected comma after object field name ',' unexpected at 4 (near '{a:[,]b:1}') [1:4]Cause. A key and its colon are present, but the value is missing and a comma follows.
Fix. Supply the value, or delete the whole member.
Object field name with no value
Triggered by:
{a}Error: Object field name with no value '}' unexpected at 3 (near '{a[}]') [1:3]{"a"}Error: Object field name with no value '}' unexpected at 5 (near '"a"[}]') [1:5]{a:{b}}Error: Object field name with no value '}' unexpected at 6 (near ':{b[}]}') [1:6]Cause. A key was followed by } with no colon and value. This is the error you get when you try to write a set, or forget the :.
Fix. Write key: value. JSON6 has no shorthand like JavaScript's { a }.
Fault while parsing field value, close with no value
Triggered by:
{a:}Error: Fault while parsing field value, close with no value '}' unexpected at 4 (near '{a:[}]') [1:4]Cause. A colon was followed directly by the closing brace.
Fix. Put a value after the colon (null or undefined if you really mean nothing).
Fault while parsing; unexpected
Triggered by:
[1,2}Error: Fault while parsing; unexpected '}' unexpected at 5 (near '1,2[}]') [1:5]{a:[1}Error: Fault while parsing; unexpected '}' unexpected at 6 (near ':[1[}]') [1:6]}Error: Fault while parsing; unexpected '}' unexpected at 1 (near '[}]') [1:1][}Error: Fault while parsing; unexpected '}' unexpected at 2 (near '[[}]') [1:2]Cause. A closing } showed up where the innermost open container is an array (or where nothing is open at all). The word "unexpected" appears twice in the full message because the generic suffix is appended to a leader that already says it.
Fix. Make the closer match its opener: [ closes with ], { with }. Indent the file consistently and the mismatch jumps out.
bad context N; fault while parsing
Triggered by:
]Error: bad context 0; fault while parsing ']' unexpected at 1 (near '[]]') [1:1]{a:]Error: bad context 4; fault while parsing ']' unexpected at 4 (near '{a:[]]') [1:4][{a:1]Error: bad context 4; fault while parsing ']' unexpected at 6 (near 'a:1[]]') [1:6]Cause. The mirror of the previous error: a ] where an object (or nothing) is open. The number after "bad context" is an internal parser state code (0 means top level), not a line number. Ignore it and read the position at the end of the message.
Fix. Match the brackets, as above.
Unexpected array open after previous value
Triggered by:
{a:1 [2]}Error: Unexpected array open after previous value '[' unexpected at 6 (near ':1 [[]2]}') [1:6]Cause. A [ started right after a finished value inside an object.
Fix. Add the comma, or give the array its own key.
fault while parsing; getting field name unexpected
Triggered by:
{{a:1}:2}Error: fault while parsing; getting field name unexpected '{' unexpected at 2 (near '{[{]a:1}:2}') [1:2]{[1]:2}Error: Fault while parsing; while getting field name unexpected '[' unexpected at 2 (near '{[[]1]:2}') [1:2]Cause. An object or array was used where a key belongs. Keys must be a bare word, a number, or a quoted string. The two messages differ only in capitalization and wording: { gives the lowercase form, [ gives "Fault while parsing; while getting field name unexpected".
Fix. Use a string key. If you wanted nesting, put the container on the value side of a colon.
fault while parsing; quote not at start of field name
Triggered by:
{a'b:1}Error: fault while parsing; quote not at start of field name ''' unexpected at 3 (near '{a[']b:1}') [1:3]{a"b:1}Error: fault while parsing; quote not at start of field name '"' unexpected at 3 (near '{a["]b:1}') [1:3]Cause. A quote character appeared in the middle of a bare key. Bare keys cannot contain quotes of any kind.
Fix. Quote the entire key: "a'b": 1.
fault while parsing; character unexpected
Triggered by:
{a b:1}Error: fault while parsing; character unexpected 'b' unexpected at 4 (near '{a [b]:1}') [1:4]{ab c:1}Error: fault while parsing; character unexpected 'c' unexpected at 5 (near 'ab [c]:1}') [1:5]Cause. Whitespace ended a bare key and another word began before the colon. Bare keys cannot contain spaces.
Fix. Quote the key ("a b": 1) or remove the space.
(outside any object, got colon out of string):parsing fault;
Triggered by:
{a:1:2}Error: (outside any object, got colon out of string):parsing fault; ':' unexpected at 5 (near 'a:1[:]2}') [1:5]"a":1Error: (outside any object, got colon out of string):parsing fault; ':' unexpected at 4 (near '"a"[:]1') [1:4]:Error: (outside any object, got colon out of string):parsing fault; ':' unexpected at 1 (near '[:]') [1:1]Cause. A : turned up where no key is waiting for a value: after a finished value, at the top level, or after a quoted string that is the whole document. Also the symptom of pasting a fragment of an object ("a": 1) without its braces. (The message says "outside any object" even for the inside-an-array and after-a-value cases.)
Fix. Wrap the fragment in { }, or remove the extra colon.
fault while parsing; '<char>' unexpected
Triggered by:
/xError: fault while parsing; 'x' unexpected at 2 (near '/[x]') [1:2]{a:/x}Error: fault while parsing; 'x' unexpected at 5 (near 'a:/[x]}') [1:5]Cause. A / must begin // or /*. Anything else after a slash is an error, which also means JSON6 has no regular expression or division syntax. (A slash followed by a space reports the space as the offending character.)
Fix. Remove the slash, or quote the value if it is a path: "/x".
Keyword and Number Errors
Bare words and digits are checked as they are read, so these errors fire at the first character that cannot belong to the token.
Incomplete keyword
Triggered by:
truError: Incomplete keyword at 3 [1:3][tru]Error: Incomplete keyword ']' unexpected at 5 (near 'tru[]]') [1:5]InfinitError: Incomplete keyword at 7 [1:7]Cause. A word that started like true, false, null, undefined, NaN or Infinity ended early. When the text simply ends, the message has no character or context part.
Fix. Spell the keyword in full, or quote the value if it was meant as a string. Keywords are case-sensitive.
fault parsing whitespace
Triggered by:
tru eError: fault parsing whitespace ' ' unexpected at 4 (near 'tru[ ]e') [1:4]{a:tr e}Error: fault parsing whitespace ' ' unexpected at 6 (near ':tr[ ]e}') [1:6]Cause. Whitespace interrupted a keyword in the middle of its spelling.
Fix. Remove the space.
Sign with no number following
Triggered by:
-Error: Sign with no number following at 1 [1:1][+]Error: Sign with no number following ']' unexpected at 3 (near '[+[]]') [1:3]{a:+}Error: Sign with no number following '}' unexpected at 5 (near 'a:+[}]') [1:5]Cause. A + or - was not followed by a digit, ., Infinity or NaN.
Fix. Complete the number, or quote the value.
Invalid number
Triggered by:
0xError: Invalid number '0x' at 2 [1:2]1eError: Invalid number '1e' at 2 [1:2]0b2Error: Invalid number '0b2' at 3 [1:3]0o8Error: Invalid number '0o8' at 3 [1:3].Error: Invalid number '.' at 1 [1:1]Cause. A number token started and then turned out to be incomplete or to use a digit outside its base: a prefix with no digits (0x), an exponent with no digits (1e), 2 in a binary literal, 8 in an octal one, or a lone decimal point.
Fix. Fix the digits. Hexadecimal, binary and octal accept underscores as separators; they do not accept an empty body.
fault while parsing number;
Triggered by:
1.2.3Error: fault while parsing number; '.' unexpected at 4 (near '1.2[.]3') [1:4]12abcError: fault while parsing number; 'a' unexpected at 3 (near '12[a]bc') [1:3]0xZZError: fault while parsing number; 'Z' unexpected at 3 (near '0x[Z]Z') [1:3]{a:1;b:2}Error: fault while parsing number; ';' unexpected at 5 (near 'a:1[;]b:2}') [1:5]Cause. A character that cannot continue the number (a second decimal point, a letter, a semicolon) followed a valid number prefix.
Fix. Quote the value if it is not really a number ("12abc"). A semicolon is never valid; use a comma.
String Escape Errors
Escapes are validated while the string is being read, so the position points inside the string.
Incomplete hexidecimal sequence
Triggered by:
"\x1"Error: Incomplete hexidecimal sequence '"' unexpected at 5 (near '\x1["]') [1:5]Cause. A \x escape needs exactly two hex digits and the string closed after one. (The word is spelled "hexidecimal" in the library's message; search for it that way.)
Fix. Write \x01.
Incomplete unicode sequence
Triggered by:
"\u12"Error: Incomplete unicode sequence '"' unexpected at 6 (near 'u12["]') [1:6]Cause. A \u escape needs exactly four hex digits.
Fix. Pad to four digits (\u0012) or use the braced form (\u{12}).
Incomplete long unicode sequence
Triggered by:
"\u{12"Error: Incomplete long unicode sequence '"' unexpected at 7 (near '{12["]') [1:7]Cause. A \u{ escape was never closed with }.
Fix. Close the brace.
(escaped character, parsing hex of \u) or (... of \x)
Triggered by:
"\xZZ"Error: (escaped character, parsing hex of \x) 'Z' unexpected at 4 (near '"\x[Z]Z"') [1:4]"\u12G4"Error: (escaped character, parsing hex of \u) 'G' unexpected at 6 (near 'u12[G]4"') [1:6]"\u{zz}"Error: (escaped character, parsing hex of \u) 'z' unexpected at 5 (near '\u{[z]z}"') [1:5]Cause. A non-hex character appeared inside an escape.
Fix. Use only 0-9, a-f, A-F. If you meant a literal backslash, double it: \\.
RangeError: Invalid code point
Triggered by:
"\u{110000}"RangeError: Invalid code point 1114112Cause. The braced escape named a code point above U+10FFFF. This is the one parse error that is a RangeError and carries no position, because it is thrown by String.fromCodePoint rather than by the parser.
Fix. Use a code point up to 10FFFF.
Strict-Mode Errors
These appear only when you pass { esStrictCompatible: true } or { forbidTemplateSubstitution: true } as the third argument to parse(). Without those options the same text parses.
Legacy octal / leading-zero numbers are not allowed when the 'esStrictCompatible' option is set
Triggered by:
0123 // parse options: {esStrictCompatible:true}Error: Legacy octal / leading-zero numbers are not allowed when the 'esStrictCompatible' option is set '1' unexpected at 2 (near '0[1]23') [1:2]Cause. Strict mode rejects 0123, because JavaScript sloppy mode reads it as octal 83 while JSON6 reads it as decimal 123.
Fix. Drop the leading zeros (123), write octal as 0o123, or quote an identifier that must keep its zeros ("0123").
Legacy octal string escapes are not allowed when the 'esStrictCompatible' option is set
Triggered by:
"\012" // parse options: {esStrictCompatible:true}Error: Legacy octal string escapes are not allowed when the 'esStrictCompatible' option is set '1' unexpected at 3 (near '"\[1]12"') [1:3]Cause. A backslash followed by a digit (\1 to \9, or \0 followed by more digits). Without the option, "\012" parses as a NUL character followed by the text 12.
Fix. Use \x0A, \u000A or \n.
Literal line terminators inside single- or double-quoted strings require the 'esStrictCompatible' option to be off
Triggered by:
"a b" // parse options: {esStrictCompatible:true}Error: Literal line terminators inside single- or double-quoted strings require the 'esStrictCompatible' option to be off ' ' unexpected at 3 (near '"a[ ]b"') [1:3]Cause. A raw newline inside a ' or " string. Back-tick strings still allow it.
Fix. Escape the newline (\n), end the line with a backslash to continue the string, or switch to a back-tick string.
Multiple consecutive signs are not allowed when the 'esStrictCompatible' option is set
Triggered by:
--5 // parse options: {esStrictCompatible:true}Error: Multiple consecutive signs are not allowed when the 'esStrictCompatible' option is set '-' unexpected at 2 (near '-[-]5') [1:2]Cause. Two or more +/- signs in a row.
Fix. Use a single sign.
Unquoted keys must be valid identifiers when the 'esStrictCompatible' option is set
Triggered by:
{a-b:1} // parse options: {esStrictCompatible:true}Error: Unquoted keys must be valid identifiers when the 'esStrictCompatible' option is set ':' unexpected at 5 (near 'a-b[:]1}') [1:5]Cause. A bare key that is neither a JavaScript identifier nor a number, such as content-type or x.y.
Fix. Quote the key.
Backtick-quoted keys are not allowed when the 'esStrictCompatible' option is set
Triggered by:
{`a`:1} // parse options: {esStrictCompatible:true}Error: Backtick-quoted keys are not allowed when the 'esStrictCompatible' option is set '`' unexpected at 2 (near '{[`]a`:1}') [1:2]Cause. A back-tick used for an object key.
Fix. Use ' or " for keys.
Template substitution ${ } is not allowed when the 'forbidTemplateSubstitution' option is set
Triggered by:
`a${b}` // parse options: {forbidTemplateSubstitution:true}Error: Template substitution ${ } is not allowed when the 'forbidTemplateSubstitution' option is set '{' unexpected at 4 (near '`a$[{]b}`') [1:4]Cause. An unescaped ${ inside a back-tick string. JSON6 treats it as plain text, but the same bytes would be a substitution if the file were ever evaluated as JavaScript.
Fix. Escape it (\${) or use a quoted string.
Streaming and API Errors
The streaming parser (JSON6.begin) shares every parse error above and adds the following. stringify() has exactly one error of its own.
context stack is not empty at flush
Error: context stack is not empty at flushCause. The streaming parser was flushed with write('') while a number was still being read inside an open object or array, as in {a:1. This is the only flush case that throws. If the cut-off comes after a string, a keyword or a closed inner container ({a:true), the flush succeeds silently and the unfinished value is simply never delivered, and an unterminated string is only reported if you call parser.finalError().
Fix. Check that the producer sent the closing bracket, or only flush at a real end of input. To validate a whole document, use JSON6.parse rather than relying on the flush.
Parser is in an error state, please reset.
Error: Parser is in an error state, please reset.Cause. After write() throws, the parser refuses further input until you call reset().
Fix. Catch the first error, log it, and call parser.reset() (or build a new parser) before writing again.
Callback function must be passed to begin, or you can't get values from the stream.
Error: Callback function must be passed to begin, or you can't get values from the stream.Cause. JSON6.begin() was called without a callback and then write() was used. begin() itself does not throw; the error appears on the first write().
Fix. Pass the callback: JSON6.begin((value) => { ... }).
JSON6.stringify unknown replacer type.
Error: JSON6.stringify unknown replacer type.Cause. The second argument to stringify() was neither a function nor an array (for example a string or an options object).
Fix. Pass null for the replacer and use the fourth argument for options: JSON6.stringify(v, null, 2, { sortKeys: false }).
What Does Not Throw
Some mistakes never raise an error. These are the ones to guard against, because bad data gets through silently. All were run against json-6 1.1.7.
| Input | Result | Why |
|---|---|---|
{a:1} x | { a: 1 } | Text after the first complete value is ignored. Same for 1 2 (gives 1), {a:1}{b:2} and {a:1}}. |
{a:1}, b:2} | { a: 1 } | A premature closing brace silently drops the rest of the file. |
{"a"b:1} | { ab: 1 } | A quoted piece directly followed by bare characters is joined into one key. |
{:1} | { '': 1 } | A missing key becomes the empty string. |
1_ | 1 | A trailing underscore separator is accepted. |
"\u{}" | '\x00' | An empty braced escape is a NUL character. |
"\q" | 'q' | An unknown escape drops the backslash. |
{"__proto__": {"x": 1}} | prototype changed | The parser assigns the prototype of the object it builds. The result has no own __proto__ key but inherits x. |
To make the first three impossible, parse the text a second time wrapped in an array with a sentinel after it, which succeeds only if the text held exactly one value, as the config files tutorial does. The JSON5 migration guide lists the differences that matter when coming from JSON5, which rejects all of these inputs.
FAQ
Why is the error not a SyntaxError?
The json-6 parser throws new Error(...) directly, so err.name is "Error". Code that catches only SyntaxError will let JSON6 errors through. Catch everything around parse() and check the message.
Can I get the line and column as numbers?
Not from a property. Extract them from the end of the message with /\[(\d+):(\d+)\]\s*$/. Errors found at the very end of input also carry this suffix, but a few (such as the code-point RangeError and "No value found in document") carry no position at all.
Why does a missing closing brace say "No value found in document"?
In JSON6.parse() the parser reports success only when it completes a value. An unclosed container never completes, so the only thing left to say is that there was no value. The streaming parser reports "context stack is not empty at flush" only when the file ends in the middle of a number, and otherwise reports nothing at all.
Do these messages change between versions?
They can. The wording was checked against json-6 1.1.7, published 10-16-2026. Treat the leader text as a search key, not a stable API, and pin the version if you match on messages.
Found a Message Not Listed Here?
The list comes straight from the json-6 source. If a new release adds a message, tell us and it will be added.