Xerobit

JSON5 to JSON Converter

Paste JSON5 and get valid JSON. This json5 to json converter strips comments, fixes trailing commas, converts single quotes to double quotes, and quotes unquoted keys. It runs entirely in your browser with no data leaving your device.

Paste JSON5 with comments, trailing commas, single quotes, or unquoted keys.

JSON Output

{
  "apiKey": "abc-123",
  "endpoints": [
    "https://api.example.com"
  ],
  "timeout": 5000
}

How to use the json5 to json converter

  1. Paste your JSON5 into the input area. It can include comments, trailing commas, single-quoted strings, unquoted keys, hexadecimal numbers, and other JSON5 features.
  2. The json5 to json conversion processes instantly: valid JSON appears in the output box. Toggle Pretty print to switch between compact and indented formatting.
  3. If the input has a syntax error, a red error message explains the problem. Fix the input and the output updates automatically.
  4. Copy the result from the output box. The output is standard JSON that any parser (JSON.parse, jq, Python json.loads, etc.) will accept.

How the conversion works

The tool runs a two-stage pipeline entirely in your browser:

  1. Parse JSON5 - A recursive-descent parser reads the text. It skips line comments (// ...) and block comments (/* ... */) wherever whitespace is allowed, so comment markers inside strings are preserved. It handles objects and arrays with optional trailing commas, unquoted keys, single-quoted strings, hexadecimal numbers, exponent notation, leading and trailing decimals, a leading plus sign, and the literals Infinity, -Infinity and NaN (which become null because standard JSON has no representation for them).
  2. Stringify as JSON - The resulting value is passed to JSON.stringify (pretty-printed or compact). If parsing fails, the error position is reported.

Worked example: input { key: 'val', } parses to an object with key "key" and string value "val" and stringifies to {"key":"val"}.

JSON5 features supported

The table lists the JSON5 extensions this converter handles. Features not listed (such as multi-line strings without escapes) are not supported and will cause an error.

FeatureExample inputJSON output
Line comment// note\n{ a: 1 }{"a":1}
Block comment/* note */{ a: 1 }{"a":1}
Trailing comma (object){ a: 1, }{"a":1}
Trailing comma (array)[1, 2, ][1,2]
Single-quoted string{ s: 'it\'s' }{"s":"it's"}
Unquoted key{ fooBar: 1 }{"fooBar":1}
Hexadecimal number{ n: 0xFF }{"n":255}
Exponent notation{ n: 1.5e2 }{"n":150}
Leading decimal{ n: .5 }{"n":0.5}
Trailing decimal{ n: 5. }{"n":5}
Infinity / NaN{ x: Infinity }{"x":null}
Positive sign{ n: +5 }{"n":5}

When to use JSON5

JSON5 is designed for human-authored configuration files. Common scenarios:

  • Config files - package.json alternatives, tool configs (ESLint, Prettier, Babel), where comments and trailing commas reduce merge conflicts.
  • Data fixtures - Test data written by developers who appreciate unquoted keys and single quotes.
  • Quick prototyping - Paste a JavaScript object literal into the converter to get valid JSON for an API call.

Do not use JSON5 for data interchange between services; always transmit standard JSON. This json5 to json tool bridges the gap: write JSON5 locally, convert once, ship JSON.

Common mistakes

  • Unterminated strings - A raw line break inside quotes is an error. Use \n, or end the line with a backslash to continue a string on the next line.
  • Missing commas - [1 2] and {a:1 b:2} are errors; JSON5 only relaxes the trailing comma.
  • Doubled commas - [1,,2] is an error; JSON5 has no sparse arrays.
  • Leading zeros - 012 is rejected. Write 12, or 0x0C for hexadecimal.
  • Functions, variables and other JavaScript - { fn: () => {} } is not JSON5, and the converter reports unknown tokens as syntax errors.
  • Very deep nesting - Input nested more than 200 levels deep is rejected with an error.

Background

JSON5 was created by Aseem Kishore in 2012 as a more human-friendly superset of JSON: every valid JSON document is also valid JSON5. It adds comments, trailing commas, single-quoted strings, unquoted keys and a few number formats, in the style of ECMAScript 5. This converter implements the JSON5 data syntax so you can write in the friendlier form and ship plain JSON without a build step.

Worked examples

ExampleInputResult
Config with comments and trailing commaJSON5 Input: { / // Server settings / host: 'localhost', / port: 3000, / enabled: true, / }; Pretty print output: yes{ / "host": "localhost", / "port": 3000, / "enabled": true / }
Array with single quotes and hexJSON5 Input: [ / 'first', / 'second', / 0xFF, / 1.5e2, / ]; Pretty print output: yes[ / "first", / "second", / 255, / 150 / ]
Nested object with unquoted keysJSON5 Input: { / user: { / name: 'Alice', / age: 30, / active: true, / }, / tags: ['admin', 'user'], / }; Pretty print output: yes{ / "user": { / "name": "Alice", / "age": 30, / "active": true / }, / "tags": [ / "admin", / "user" / ] / }

FAQ

Does this tool send my data to a server?

No. All conversion happens in your browser. Nothing is uploaded or logged.

Can I convert a large file (10 MB+)?

Inputs up to 2 MB are accepted. The parser runs in your browser and handles a few hundred kilobytes in well under a second on a typical device; larger input is rejected with an error message.

Why do Infinity and NaN become null?

Standard JSON has no literals for Infinity, -Infinity or NaN, and JavaScript's JSON.stringify writes them as null. If you need to keep them, replace them with strings before converting.

Are multi-line strings supported?

Only with a backslash at the end of the line (line continuation) or an explicit \n escape. A raw line break inside quotes is a syntax error.

Can I use this from the command line?

This is a browser tool. For command-line use, the json5 npm package includes a converter: npx json5 -c file.json5.

What if my input is already valid JSON?

The json5 to json converter passes it through unchanged (aside from optional pretty-printing). Valid JSON is valid JSON5.

Does it handle Unicode correctly?

Yes. Unicode characters in strings are preserved, and the \uXXXX and \xXX escapes are decoded. The converter also accepts the ES2015 form \u{1F600}, which is not part of the JSON5 spec, and writes the resulting character into the JSON output.