JSON6 Parse Errors

How to diagnose and fix JSON6 parsing errors.

TL;DR: Parse errors usually point to the exact line and character where the problem is. Common causes: missing commas, unclosed strings, invalid unquoted keys, or using JSON.parse instead of JSON6.parse.

Understanding Error Messages

JSON6 parse errors include helpful information to locate the problem:

SyntaxError: JSON6: invalid character 'b' at 2:3 Line 2, Column 3 | v { a: 1 b: 2 } ^-- Missing comma here

Error Format

Part Meaning
SyntaxError The error type (always SyntaxError for parse errors)
JSON6: Indicates this is a JSON6-specific error
invalid character 'b' What the parser found when it expected something else
at 2:3 Line 2, column 3 (1-indexed)

Common Parse Errors

Missing Comma

Error: invalid character or unexpected token

Wrong

{ name: 'app' // Missing comma! version: '1.0' }

Correct

{ name: 'app', // Comma added version: '1.0', }

Unclosed String

Error: unterminated string or unexpected end of input

Wrong

{ message: 'Hello world // Missing quote! }

Correct

{ message: 'Hello world', }

Invalid Unquoted Key

Error: invalid identifier character

Wrong

{ my-key: 'value', // Hyphen not allowed! 123abc: 'value', // Can't start with number! }

Correct

{ 'my-key': 'value', // Quote it '123abc': 'value', // Quote it }

Reserved Word as Key

Error: invalid identifier

Wrong

{ class: 'container', // Reserved! import: 'module', // Reserved! }

Correct

{ 'class': 'container', 'import': 'module', }

Reserved words: break, case, catch, class, const, continue, default, delete, do, else, export, extends, finally, for, function, if, import, in, instanceof, new, return, super, switch, this, throw, try, typeof, var, void, while, with, yield, null, true, false

Unclosed Multi-line Comment

Error: unexpected end of input

Wrong

{ /* This comment is never closed key: 'value', }

Correct

{ /* This comment is properly closed */ key: 'value', }

Unmatched Brackets

Error: unexpected end of input or unexpected token

Wrong

{ items: [1, 2, 3 // Missing ] }

Correct

{ items: [1, 2, 3], }

Debugging Tips

Check the Line Number

The error message tells you exactly where to look. Go to that line and check the characters before and after the column position.

Use an Editor with JSON6 Support

VS Code with the JSON6 extension will show errors inline as you type. Set up VS Code for JSON6.

Try Online Validation

Paste your JSON6 into an online validator to get detailed error messages.

Binary Search for Errors

For large files, remove half the content and see if it parses. Repeat to narrow down the location.

Convert to Standard JSON

Remove all JSON6-specific features (comments, trailing commas, unquoted keys) and try parsing as JSON. This can help isolate whether the issue is JSON6-specific.

Using the Wrong Parser

A common mistake is using JSON.parse() instead of JSON6.parse().

Remember: The native JSON.parse() does NOT support comments, trailing commas, or other JSON6 features. You must use a JSON6 library.

Wrong

// This will fail on JSON6 content! const data = JSON.parse(json6String); // SyntaxError: Unexpected token /

Correct

import JSON6 from 'json6'; // This handles JSON6 features const data = JSON6.parse(json6String);

Still Having Issues?

Check our other troubleshooting guides or validate your JSON6 online.