JSON validator & beautifier

5 of 2 ratings
JSON validator & beautifier

JSON validator & beautifier is a free tool that checks whether JSON is syntactically valid and formats valid content so that its structure is easier to read.

What does JSON validation and beautification do?

JSON validation confirms that input follows the JSON grammar, while beautification presents valid objects and arrays with consistent spacing and indentation. This is useful when debugging API responses, checking configuration before deployment or reading compact data supplied by a third party.

JSON has stricter syntax than a JavaScript object literal. Property names must use double quotation marks, strings cannot use single quotation marks, and neither objects nor arrays may have trailing commas. Comments, undefined, NaN and Infinity are also outside the JSON specification.

This tool uses PHP's json_decode function on the server. Your input travels to the server over HTTPS and is not stored. It does leave your device, so redact passwords, access tokens and personal data if your organisation's handling rules do not permit them to be sent to an external server.

How do I validate and beautify JSON?

Paste the content into the JSON field and run the tool. For a useful result, include one complete JSON value rather than part of an object copied from a log line.

  1. Copy the raw response, configuration block or other JSON value without surrounding console labels.
  2. Paste it into the JSON field, preserving quotation marks and escape characters.
  3. Run the validation and inspect either the formatted result or the reported failure.
  4. If validation fails, correct the first apparent syntax problem and run it again. One missing quotation mark can cause several later characters to be interpreted incorrectly.
The JSON validator & beautifier tool on digily.link, showing its input form

The four permitted whitespace characters between JSON tokens, space (U+0020), tab (U+0009), line feed (U+000A) and carriage return (U+000D), are insignificant, so they may be added or removed without changing the data. Whitespace inside a quoted string is data and must remain unchanged. Punctuation inside strings is also preserved, although quotation marks, backslashes and control characters need the appropriate escape sequence.

How should I read the validation result?

A successful result means PHP could decode the input as JSON, while a failure means the parser could not interpret it as one complete valid JSON value. Beautification then makes the nesting and boundaries of valid objects and arrays visible.

Common causes of failure include:

  • a trailing comma before } or ];
  • an unquoted property name such as {name: "Ada"};
  • single-quoted strings;
  • a missing comma between properties or array elements;
  • an unescaped double quotation mark or backslash inside a string;
  • an incomplete object, array or string;
  • invalid UTF-8 input or a raw control character inside a string;
  • an integer part with unnecessary leading zeroes, such as 01 or -01, or non-JSON values such as NaN.

An empty field is not valid JSON. By contrast, an isolated value such as 42, true, null or "hello" is valid JSON even though it is not an object or array. Very deeply nested content may also exceed the decoder's nesting limit.

Syntax validation does not confirm that the data matches an API contract. A document can be valid JSON while containing a string where an application expects a number, omitting a required property or using an unacceptable date format. Use JSON Schema or application-level checks for those requirements.

Example result produced by the JSON validator & beautifier tool

Worked JSON examples

Valid compact input:

{"name":"Ada","active":true,"roles":["admin","editor"]}

The beautified result presents the properties and array elements on separate, indented levels. The values remain a string, a Boolean and an array respectively. Formatting changes presentation, not the underlying data types.

Invalid input with a trailing comma:

{"name":"Ada","active":true,}

This fails because JSON does not permit a comma after the final property. Remove that comma to make the object valid.

Accented and non-Latin text can appear directly in JSON strings when the input is valid UTF-8. For example, {"city":"Zürich","greeting":"こんにちは"} is valid. JSON escape notation such as \u00fc is another valid representation of certain Unicode characters, although surrogate pairs are needed for characters outside the Basic Multilingual Plane.

When is beautifying JSON not worth doing?

Beautification is unnecessary when only a machine will read the JSON and no human inspection or version-control review is planned. Extra indentation and line breaks in JSON increase the number of bytes transferred, so production responses are commonly sent in compact form.

There is also little value in minifying JSON that is already compact. Repeated minification cannot make fixed property names or string values shorter, and changing those values would change the data. For deployable JavaScript rather than JSON data, the JS minifier is the more appropriate operation.

Beautification is most useful when inspecting JSON structures or values during debugging, code review and pre-deployment checks. It exposes mismatched nesting, makes large arrays easier to scan and produces cleaner diffs when configuration is committed to Git. It does not repair malformed JSON automatically or decide what an ambiguous fragment was intended to mean.

Frequently asked questions

Can JSON contain comments?

No. Standard JSON has no comment syntax, so // comment and /* comment */ cause validation to fail. If comments are needed in a configuration file, use a format that defines them, or remove the comments before passing the content to a strict JSON parser.

Will duplicate property names be rejected?

Not necessarily. The JSON specification says member names within an object should be unique, but duplicate names are not reliably treated as a syntax error by parsers. PHP decoding commonly retains the later value, so detect duplicates before validation if preserving every occurrence matters.

Can I validate a JSON Lines file?

Not as one JSON document. JSON Lines, also called NDJSON, contains a separate JSON value on each line, whereas a normal JSON parser expects one top-level value. Validate each line independently or convert the records into a single JSON array.

Does the order of object properties matter?

Applications should not rely on JSON object property order. Arrays are ordered, but objects represent collections of named members, and another parser or serialiser may emit those members differently. If sequence carries meaning, put the values in an array.

Why can a JSON file fail even though it looks correct?

An invisible byte-order mark, malformed UTF-8 or an unescaped control character can make apparently correct text fail. Copying from a terminal can also introduce prefixes such as status labels or timestamps. Inspect the raw bytes or open the file in an editor that can display encoding and control characters.

Final checks

Before deploying corrected JSON, compare data types as well as visible values, check that escape sequences have not changed, and run the consuming application or its schema validation. Keep an untouched copy of the original response when diagnosing third-party data so that formatting does not obscure the source of the fault.

Popular Tools