Why strict JSON is still needed
Human-edited config files have drifted away from strict JSON. VS Code’s settings.json, tsconfig.json and .eslintrc.json allow comments and trailing commas (often called JSONC), and JSON5 goes further with unquoted keys, single quotes and hex numbers. But JSON.parse, Python’s json module, jq and most APIs reject all of that.
Converting gives you a file those tools can read: for example to post a config to an API, diff it with jq, or embed it in another JSON document. Read JSON with comments for the background on JSONC versus JSON5.
What gets rewritten
The input is parsed as JSON5 (or as JSONC when it only uses comments and trailing commas) and printed as standard JSON with two-space indentation:
// lineand/* block */comments are removed, and an info note confirms it.- Unquoted keys get double quotes:
{port: 8080}becomes{"port": 8080}. - Single-quoted strings become double-quoted, with inner quotes escaped as needed.
- Trailing commas after the last item or property disappear.
- Hexadecimal numbers (
0x1F), leading or trailing decimal points (.5,5.) and an explicit plus sign (+1) become ordinary decimal numbers. - Strings continued over several lines with a backslash are joined into one line.
Key order is kept. When a key appears twice, the later value wins, matching how JSON5 parsers behave.
Values JSON cannot express
JSON5 allows Infinity, -Infinity and NaN, but strict JSON has no spelling for them. They are written as null — the same thing JSON.stringify does — so check any keys that held them.
Numbers are read as JavaScript doubles, so integers longer than about 15–16 digits lose precision: 12345678901234567890 comes out as 12345678901234567000. If you have IDs that large, quote them as strings in the JSON5 source before converting. The big integers in JSON guide explains why this happens.
Comments are gone for good
Strict JSON cannot hold comments, so they are not moved anywhere: they are deleted. Keep the JSON5 or JSONC file as your source and regenerate the JSON whenever it changes, rather than editing the output by hand.
There are no conversion options. Syntax errors are reported with a line and column; JSON5 is permissive, so most errors are a missing comma between properties or an unclosed bracket or comment. Your configuration never leaves the browser while this runs.
Tips for config files
- If you only need to check that a JSONC file is well-formed, the JSON5 formatter keeps the comments while it tidies the layout.
- When a tool rejects a file with “Unexpected token /”, the cause is almost always a comment; converting here shows the file the way a strict parser needs it.
- Generated JSON is safe to minify afterwards with the JSON minifier if size matters, for example when embedding it in an environment variable.
Examples
tsconfig.json with comments
A JSONC file: comments and the trailing commas are removed, and everything else is unchanged.
{
// Language and environment
"compilerOptions": {
"target": "ES2022",
"module": "ESNext", /* bundler handles modules */
"strict": true,
"paths": { "@/*": ["./src/*"], },
},
"include": ["src"],
}
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"strict": true,
"paths": {
"@/*": [
"./src/*"
]
}
},
"include": [
"src"
]
}
Full JSON5 syntax
Unquoted keys gain quotes, single quotes become double quotes, and .5, 0xFF and +3 become plain decimal numbers.
// app config
{
name: 'checkout',
port: 8080,
hosts: ['a.example.com', 'b.example.com',],
ratio: .5,
mask: 0xFF,
retry: { max: +3, backoff: 'exponential' },
}
{
"name": "checkout",
"port": 8080,
"hosts": [
"a.example.com",
"b.example.com"
],
"ratio": 0.5,
"mask": 255,
"retry": {
"max": 3,
"backoff": "exponential"
}
}
Common errors and how to fix them
| Error | Cause | Fix |
|---|---|---|
Invalid character 'b'Explained | Two properties are missing the comma between them, as in {a: 1 b: 2}. | Add the comma after the first value. |
Invalid end of inputExplained | A block comment, string or bracket is never closed, so the file ends unexpectedly. | Close the /* comment */ or bracket that the line number points near. |
Invalid character 'u'Explained | The source contains undefined or another JavaScript identifier as a value, which JSON5 does not allow. | Replace it with null or a quoted string. |
Invalid character '\n' | A string contains a raw line break without a backslash continuation. | Write the break as \n inside the string, or end the line with a backslash. |
Frequently asked questions
What is the difference between JSON5 and JSONC?
JSONC is JSON plus comments and trailing commas, as used by VS Code and TypeScript. JSON5 additionally allows unquoted keys, single quotes, hex numbers and more. This converter accepts both.
Can comments be kept in the output?
No, strict JSON has no comment syntax. They are removed, and the tool tells you when that happened.
What happens to Infinity and NaN?
They become null, because JSON cannot represent them. Replace them in the source if null is not acceptable.
Are large integers safe?
Not beyond about 15 significant digits: JSON5 numbers are parsed as doubles and rounded. Quote big IDs as strings before converting.