JSON Formatter & Validator Widget
Add a JSON formatter to your API docs or tutorial. Readers paste JSON and get it indented, minified or validated, and a mistake is pointed out by line and column with the offending line shown.
Live preview
Exactly what your visitors will seeUnder the widget on your page: Powered by A2Z Tools
Embed code
<iframe src="https://a2z.tools/embed/w/json-formatter" title="JSON Formatter & Validator by A2Z Tools" width="100%" height="940" style="border:0;width:100%" loading="lazy" allow="clipboard-write"></iframe>
A plain iframe. Works everywhere, including site builders that strip scripts. Adjust height if your content needs more room.
<div data-a2z-widget="json-formatter" data-height="940"></div> <script async src="https://a2z.tools/embed.js"></script>
Adds a small script (what it does) that sizes the widget to fit its content, loads it lazily and keeps it isolated from your page's CSS.
Works with
How it works
The widget uses its own JSON parser rather than JSON.parse followed by JSON.stringify. That matters because the round trip through JavaScript numbers silently rounds large integers (12345678901234567890 becomes 12345678901234567000) and rewrites 1.10 as 1.1. The parser keeps every number and string exactly as written, preserves key order and duplicate keys, and only re-orders keys when sorting is switched on. It is iterative, so deeply nested input cannot overflow the stack; nesting is capped at 512 levels. On a syntax error it reports the line, the column and a plain-English reason such as a trailing comma, a single-quoted string or NaN, followed by the offending line with a caret under the exact character. Line and column are counted from 1, and the column counts Unicode code points, so an emoji earlier on the line counts as one column rather than two. The grammar it enforces is the strict one of RFC 8259 and ECMA-404, so anything it accepts will also load in Python's json module, Go's encoding/json or a browser's JSON.parse; anything it rejects would be refused by at least one of them. Validate mode only checks and summarises (top-level type, nesting depth, number of values) without rewriting the text, which is useful when a reader wants to confirm a webhook body before pasting it into a ticket.
Method
- Grammar: RFC 8259 / ECMA-404 JSON (no comments, no trailing commas, double-quoted strings only)
- Numbers and strings are copied from the source text, never re-serialised
- Format: one value per line, indented by 2 spaces, 4 spaces or a tab; Minify: no whitespace
- Sort keys: object keys ordered by code unit, recursively; arrays keep their order
- Limits: 1,000,000 characters, 512 nesting levels
Worked examples
Long IDs and trailing zeros survive formatting
Inputs: {"id":12345678901234567890,"price":1.10,"tags":["a","b"]} - Format, 2 spaces
Result: { "id": 12345678901234567890, "price": 1.10, "tags": [ "a", "b" ] }
JSON.parse followed by JSON.stringify would print 12345678901234567000 and 1.1; this parser copies both numbers exactly as typed.
A trailing comma is located precisely
Inputs: {"name":"A2Z","tags":["a","b",],} - Format
Result: Error at line 1, column 30: Trailing comma - remove the comma before ']'
RFC 8259 has no trailing commas. Column 30 is the comma after "b"; the excerpt puts a caret under it.
Duplicate keys are reported, not silently dropped
Inputs: {"b":1,"a":2,"b":3} - Validate
Result: Valid JSON; Object, nested 1 level; 4 values; warning: Duplicate keys: b
RFC 8259 says names SHOULD be unique but does not forbid repeats, so the document is valid; most parsers would keep only b = 3.
Limitations
- Strict JSON only: JSON5, JSONC comments, NDJSON (one document per line) and trailing commas are reported as errors, not repaired.
- Input is capped at 1,000,000 characters and 512 nesting levels to keep the page responsive.
- Sorting compares keys by UTF-16 code unit, not by locale, so accented or upper-case keys may not sort the way a dictionary would.
- It checks syntax only; it does not validate against a JSON Schema or check data types of particular fields.
Where publishers use it
- REST API documentation where readers inspect sample responses
- Beginner JavaScript or Python tutorials explaining why a JSON file will not load
- Internal wikis and runbooks where support staff tidy webhook payloads before filing a ticket
- Course pages about configuration files such as package.json or tsconfig.json
Questions
Why does my number look different in other formatters?
Most online formatters parse JSON into JavaScript numbers, which only hold about 15-17 significant digits, so long IDs get rounded. This widget copies numbers exactly as they appear in your input.
Does it accept comments or trailing commas?
No. Those are JSON5 or JavaScript features, not JSON. The widget reports them as errors with their position so you can remove them.
What happens with duplicate keys?
They are kept in place and listed in a warning, because most parsers silently keep only the last value.
Is the JSON sent to a server?
No. Parsing and formatting happen in the visitor's browser.
Sources
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format - IETF . Grammar, number and string syntax; December 2017
- ECMA-404: The JSON data interchange syntax, 2nd edition - Ecma International . Syntax definition equivalent to RFC 8259; December 2017
Cite or recommend this tool
If you reference this tool in an article, course or documentation, these formats are ready to copy. They are optional - nothing is added to your site unless you paste it.
A2Z Tools JSON Formatter & Validator https://a2z.tools/json-formatter
<a href="https://a2z.tools/json-formatter">A2Z Tools JSON Formatter & Validator</a>
[A2Z Tools JSON Formatter & Validator](https://a2z.tools/json-formatter)
JSON Formatter & Validator by A2Z Tools - https://a2z.tools/json-formatter
Related widgets
-
Convert a JSON array of objects to CSV and CSV back to JSON, with RFC 4180 quoting.
-
Read a JSON Web Token's header and claims, with exp, nbf and iat shown as dates.
-
Encode text to Base64 or decode it, with proper UTF-8 and an optional URL-safe alphabet.
-
Compare two versions of a text line by line or word by word, with additions and removals marked.
-
Percent-encode or decode text and URLs, and find the exact position of a malformed escape.
-
Generate 1 to 100 random v4 or time-ordered v7 UUIDs in several formats.