User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
Category JSON Tools
JSON5 Input
JSON Output
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

About

JSON5 extends JSON with ECMAScript 5.1 syntax features: unquoted identifier keys, single-quoted strings, trailing commas, hexadecimal integers, Infinity, NaN, and inline or block comments. Standard parsers (JSON.parse) reject all of these. Feeding a JSON5 config file to a strict JSON consumer causes silent failures or crashes in CI pipelines, build tools, and API endpoints. This converter implements a full recursive-descent JSON5 parser entirely in the browser. No data leaves your machine. It tokenizes input character-by-character without eval or Function constructors, so malicious payloads cannot execute.

Output indentation is configurable from 0 (minified) to 8 spaces. The parser reports errors with exact line and column numbers. Limitation: files exceeding ~50 MB may exhaust browser memory on low-end devices. For extremely large config trees, split input into smaller chunks.

json5 json converter json5-to-json parser format validate

Formulas

JSON5 parsing follows a recursive descent strategy. The converter tokenizes input into a stream, then builds a value tree. Conversion to standard JSON uses the native serializer:

output = JSON.stringify(parseJSON5(input), replacer, space)

Where input is the raw JSON5 string, replacer is NULL (identity), and space is the indentation width (0 - 8).

Non-finite numeric literals are handled with a lossy mapping:

{
Infinity β†’ NULL-Infinity β†’ NULLNaN β†’ NULL

Hexadecimal integers undergo base conversion: v = parseInt(hex, 16). The parser validates identifiers against ECMAScript 5.1 IdentifierName production using Unicode category checks for ID_Start and ID_Continue code points.

Reference Data

JSON5 FeatureJSON5 Syntax ExampleStandard JSON EquivalentStatus in JSON
Unquoted keys{ key: 1 }{ "key": 1 }Not allowed
Single-quoted strings"hello""hello"Not allowed
Trailing commas[1, 2, 3,][1, 2, 3]Not allowed
Single-line comments// commentRemovedNot allowed
Multi-line comments/* comment */RemovedNot allowed
Hexadecimal integers0xFF255Not allowed
Leading decimal point.50.5Not allowed
Trailing decimal point5.5.0Not allowed
Positive sign+11Not allowed
InfinityInfinitynull (lossy)Not allowed
NaNNaNnull (lossy)Not allowed
Multiline strings"line1\
line2"
"line1line2"Not allowed
Escape: \v"\v""\u000b"Not allowed
Escape: \0"\0""\u0000"Not allowed
Escape: \x hex"\x41""A"Not allowed
Null valuenullnullAllowed
Boolean valuestrue / falsetrue / falseAllowed
Double-quoted strings"hello""hello"Allowed
Nested objects{ a: { b: 1 } }{ "a": { "b": 1 } }Allowed (quoted)
Arrays[1, 2, 3][1, 2, 3]Allowed

Frequently Asked Questions

Standard JSON has no representation for non-finite numbers. The converter maps Infinity, -Infinity, and NaN to null. This is a lossy conversion. If your downstream consumer needs these values, consider encoding them as strings (e.g., "Infinity") and parsing them application-side.
No. JSON5 follows ECMAScript comment rules. Block comments (/* ... */) do not nest. A */ sequence inside a block comment terminates it immediately, which will likely cause a parse error on the remaining text. Single-line comments (//) end at the next line terminator.
Unquoted keys must conform to ECMAScript 5.1 IdentifierName. The first character must be a Unicode letter, $, _, or a Unicode escape sequence (\uXXXX). Subsequent characters may also include digits and combining marks. Keys like cafΓ© or $price are valid. Keys starting with a digit (e.g., 3dModel) are not and must be quoted.
Yes. The parser builds an ordered key list during object parsing and JSON.stringify preserves insertion order for string keys in modern engines. Integer-like keys (e.g., "0", "1") may be reordered by some engines per the spec, but this is rare in practice for config files.
The converter processes files entirely in browser memory. For inputs under 100 KB, parsing is synchronous and near-instant. Larger files are processed in a Web Worker to avoid UI freezing. Practical upper limit is approximately 50 MB depending on device RAM. For files exceeding this, split them or use a CLI tool like the json5 npm package.
This tool performs one-way conversion: JSON5 β†’ JSON. Standard JSON is already valid JSON5, so the reverse direction is trivial (the file is already compatible). If you want to add JSON5 features like comments or trailing commas, that requires a formatter/pretty-printer with style preferences, which is a different tool category.
JSON5 allows a backslash before a line terminator inside a string to continue it on the next line. The line terminator and backslash are stripped from the result. For example, "hello\↡world" becomes "helloworld" (no space, no newline). To preserve a newline character, use \n explicitly.