How to format JSON and fix invalid JSON

By DataLens by Flazetech

To format JSON, paste a valid JSON document into a formatter, choose indentation, and format it. If validation fails, correct the syntax first. DataLens shows the parser error and provides code and tree views, so you can check nested data before copying or downloading the result.

Open JSON formatter

Format a JSON object in three steps

Open the JSON formatter and paste your document into JSON input, or upload a .json file. Select 2 spaces, 4 spaces, or tabs, then choose Format JSON. Ctrl or Command + Enter runs the same action. Auto-format can update the result while you edit.

Start with a small example. The input below contains an object with a project name, a boolean and an array. Formatting exposes the hierarchy without changing the order of the array. Compare the input and output, then try your own response or configuration file.

Compact JSON input
{"project":"DataLens","ready":true,"items":[1,2]}
Formatted JSON output
{
  "project": "DataLens",
  "ready": true,
  "items": [
    1,
    2
  ]
}

Why does the JSON validator report an error?

JSON strings and property names use double quotes. A trailing comma after the last member is invalid, and every opening brace or bracket needs a matching closing one. A JavaScript object literal is not necessarily valid JSON. Fix the first reported problem, then validate again: later errors may depend on it.

The formatter reports invalid input rather than guessing a repair. Check the quoted section and the preceding line. Pasting a response that starts with HTML, such as a login page or an error page, also fails because that response is not JSON.

ProblemInvalid exampleValid JSON
Single quotes{'name':'Alex'}{"name":"Alex"}
Trailing comma{"ready":true,}{"ready":true}
Unquoted property{count:2}{"count":2}
Unclosed array[1,2[1,2]

Reference: MDN: JSON.parse syntax errors.

Formatter, beautifier, validator or minifier?

Choose the operation that matches your next task. Beautify and pretty-print are common names for formatting. Validation checks syntax; it does not prove that an API accepts the fields or that a value meets a business rule. Schema validation is a separate operation and is not provided by this formatter.

OperationUse it when
Format / beautifyYou want indentation and line breaks for reading.
ValidateYou need to check whether the input parses as JSON.
MinifyYou want a compact representation without indentation.
Tree viewYou need to expand nested objects or copy a field path.
Sort keysYou want a consistent property order for inspection.

Check values before copying the result

Use code view to search the output, or tree view to inspect one branch at a time. Arrays keep their item order. Root values such as null, false, a number or a string are valid JSON too; a document does not have to start with an object.

DataLens uses JavaScript parsing and number precision. Store exact long identifiers and decimals as strings when their exact representation matters. Duplicate property names should be corrected in the source: parsing can keep only the last value, so reformatting is not an archival copy of the original text.

Formatting runs in your browser. Sharing is a separate action and makes the supplied content available through the link or configured sharing service. For two versions of a response, move to JSON diff; to extract selected values, use the JSONPath tester.

Reference: RFC 8259: JSON values, objects and numbers.

Try it with your own data

The examples are ready to copy. Open the json formatter to inspect your input and review the result.

Open JSON formatter