Parse Errors
How to diagnose and fix JSON5 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 JSON5.parse.
Understanding Error Messages
JSON5 parse errors include helpful information to locate the problem:
SyntaxError: JSON5: invalid character 'b' at 2:3 Line 2, Column 3 | v { a: 1 b: 2 } ^-- Missing comma hereError Format
| Part | Meaning |
|---|---|
SyntaxError | The error type (always SyntaxError for parse errors) |
JSON5: | Indicates this is a JSON5-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 JSON5 Support
VS Code with the JSON5 extension will show errors inline as you type. Set up VS Code for JSON5.
Try Online Validation
Paste your JSON5 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 JSON5-specific features (comments, trailing commas, unquoted keys) and try parsing as JSON. This can help isolate whether the issue is JSON5-specific.
Using the Wrong Parser
A common mistake is using JSON.parse() instead of JSON5.parse().
Remember: The native JSON.parse() does NOT support comments, trailing commas, or other JSON5 features. You must use a JSON5 library.
Wrong
// This will fail on JSON5 content! const data = JSON.parse(json5String); // SyntaxError: Unexpected token /Correct
import JSON5 from 'json5'; // This handles JSON5 features const data = JSON5.parse(json5String);Still Having Issues?
Check our other troubleshooting guides or validate your JSON5 online.