← JSON
JSON·Guide
All tools

JSON

The tool shows JSON as a tree while you edit it, points at the line and column of an error, and formats or minifies it. Numbers are kept exactly as written: JSON.parse turns a 64-bit ID such as 12345678901234567890 into 12345678901234567000; the tool shows and copies the original.

1The JSON library

lib/json.js is a JavaScript module with no dependencies and no user interface. It exports JsonText (static methods) and RawNumber (a number literal kept as written).

<script type="module">
	import { JsonText } from "../lib/json.js";

	const result = JsonText.tryParse(text);
	if (result.error) {
		console.log(result.error.line, result.error.column, result.error.message);
	} else {
		console.log(JsonText.stringify(result.value, 2));   // big numbers written back exactly
	}
</script>
MethodWhat it does
JsonText.parse(text)Like JSON.parse, but numbers that wouldn't survive a round trip become RawNumber objects holding the literal (in engines with JSON source-text access: Chrome 114+, Safari 17.4+). A byte order mark is ignored.
JsonText.tryParse(text){ value }, or { error: { message, line, column } } with the engine's message cleaned up.
JsonText.stringify(value, indent)Like JSON.stringify, writing raw numbers back as they were.
JsonText.describe(value)"object · 3 keys", "array · 10 items", "string"…
JsonText.isRawNumber(value)Whether a value is a kept literal (its text is value.source).
new RawNumber(source)A kept literal: source is its text. value instanceof RawNumber is the same test as isRawNumber.