Skip to content

JSON5 to JSON

Validate JSON5 and convert it to standard JSON.

OUTPUT: JSON
0 chars

// What JSON5 adds to JSON

Comments and flexible quoting

Single-line and block comments, unquoted keys, single-quoted keys and values, and trailing commas are all accepted.

Numbers and special values

Hexadecimal literals, leading or trailing decimal points, signed numbers, Infinity and NaN are parsed by the JSON5 library.

Predictable JSON output

Valid input is written with two-space indentation. Infinity and NaN become null, and a duplicate key keeps its last value.

// From a config file to strict JSON

IN

{ // comment unquoted: 'hello', list: [1, 2,], }

OUT

{ "unquoted": "hello", "list": [ 1, 2 ] }

Comments and trailing commas disappear; keys gain double quotes and the result is indented with two spaces.

// Edge cases worth knowing

What is JSON5?

A superset of JSON designed for configuration files. It adds comments, unquoted keys, single quotes, trailing commas and extra number formats. It is not a JSON standard, so convert it before sending it to a strict parser.

What happens to Infinity and NaN?

They are valid in JSON5 but have no JSON representation. Standard serialization turns them into null, the same behaviour as JSON.stringify.

Can JSON be parsed here too?

Yes. Valid JSON is also valid JSON5, so pasting strict JSON gives you a neatly indented version of the same data.

// After converting

  • >JSON Formatter — read the result as a tree or edit a value in place
  • >JSON Diff — compare the converted file with an earlier version