JSON Formatter and Validator

Beautify, minify and validate JSON with the same parser your code uses, then pull fields out of large responses with JSONPath. Runs in your browser.

The interactive tool loads here when JavaScript runs.

About this tool

What is the JSON Formatter?

The JSON Formatter takes raw JSON, checks that it parses, and gives it back either pretty-printed with two-space indentation or minified onto a single line. It also runs JSONPath queries against the document, so you can pull one field out of a large API response instead of scrolling for it.

Validation here means syntax validation: the input is run through the same JSON.parse that browsers and Node.js use, so if it passes here it will parse in your code. The badge reports Valid or Invalid as you type, but it does not point at the line and column of the error, and it does not check your data against a JSON Schema.

Because the output is produced by parsing and re-serializing, a few things change on the way through: integers larger than 2^53 lose precision, and when an object repeats a key only the last value survives. Both are standard JSON.parse behaviour, and both are worth knowing before you paste the result back into a config file.

  • Syntax validation with the browser's native JSON parser
  • Beautify with two-space indentation or minify to one line
  • JSONPath queries powered by the jsonpath-plus library
  • Copy to clipboard and download as a .json file
  • Runs locally in your browser; your JSON is not uploaded
Read the guide: JSON Formatting, Validation and JSONPath: A Practical Guide

Updated

How to use the JSON Formatter

  1. Paste your JSON into the Input JSON box. The badge next to it shows Valid or Invalid as soon as it can be parsed.
  2. Click Beautify for indented, readable output, or Minify to strip all whitespace for transport or storage.
  3. To extract data, type a JSONPath expression such as $.users[0].email into the JSONPath Query field and click Execute Query.
  4. Copy the formatted output to the clipboard, or download it as formatted.json.

Worked examples

Filter an array with JSONPath

Input

{"orders":[{"id":101,"status":"shipped"},{"id":102,"status":"pending"},{"id":103,"status":"shipped"}]}  with  $.orders[?(@.status=='shipped')].id

Output

[101, 103]

The filter keeps orders whose status is shipped, then .id takes each id. Results always come back as an array, even when only one value matches.

A large ID loses precision

Input

{"id": 12345678901234567890}

Output

{"id": 12345678901234567000}

JavaScript numbers are 64-bit floats, so integers above 9,007,199,254,740,991 are rounded when parsed. APIs that use 64-bit IDs (Twitter, Discord) send them as strings for this reason.

Background and insight

JSON was described by Douglas Crockford in the early 2000s as a subset of JavaScript object literal syntax, and it is now standardized as RFC 8259 and ECMA-404. Its grammar is deliberately tiny: objects, arrays, strings, numbers, true, false and null. That small grammar is the reason it won, and also the reason it is unforgiving. Trailing commas, single-quoted strings, comments and unquoted keys are all legal in a JavaScript file and all illegal in JSON.

In practice most "invalid JSON" bugs come from three places: a config file that someone edited by hand and left a trailing comma in, a log line that was truncated mid-object, and a string that was copied out of a JavaScript console with single quotes. A formatter that fails loudly on exactly those cases is more useful than one that quietly repairs them, because the code that consumes the JSON will not repair them either.

JSONPath, first proposed by Stefan Goessner in 2007 and standardized as RFC 9535 in 2024, does for JSON what XPath does for XML. An expression like $.items[*].id reads naturally once you know that $ is the root, dots walk into objects and [*] means every element of an array. This page uses the jsonpath-plus library, which follows Goessner's original syntax, so a few RFC 9535 details (such as filter syntax without parentheses) may behave differently.

Common use cases

  • Reading API responses

    Paste a minified response from curl or the browser network tab and beautify it to see the structure at a glance.

  • Finding a broken config

    Drop in a package.json or tsconfig that a tool refuses to load and see immediately whether it is a syntax problem.

  • Pulling fields from large payloads

    Use a JSONPath query like $..id to collect every id in a deeply nested document without writing a script.

  • Shrinking fixtures

    Minify JSON test fixtures or seed data before embedding them in code or environment variables.

Tips and limitations

  • tsconfig.json and VS Code settings files are JSONC (JSON with comments). They will show Invalid here even though the tools that read them accept them.
  • If the badge says Invalid and the error is not obvious, look at the end of the input first: truncated logs and a missing closing brace are more common than errors in the middle.
  • Duplicate keys are not an error in JSON.parse. {"a":1,"a":2} becomes {"a":2} after beautifying, so a formatter can hide a duplicated key.
  • Use .. (recursive descent) carefully on big documents: $..id matches ids at every depth, including ones inside nested objects you did not mean to include.
  • Minifying does not change the data, but beautifying a minified file before committing it makes later diffs readable line by line.

Sources and further reading

  1. RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format, IETF. The JSON grammar this validator enforces
  2. ECMA-404: The JSON Data Interchange Syntax, Ecma International
  3. RFC 9535: JSONPath: Query Expressions for JSON, IETF. The 2024 JSONPath standard
  4. JSONPath: XPath for JSON, Stefan Goessner. The 2007 article that introduced the query syntax
  5. JSON.parse(), MDN Web Docs

Frequently asked questions

Why does my JSON fail validation when it works in JavaScript?

Because JavaScript object literals accept syntax that strict JSON rejects. Trailing commas, single-quoted strings, comments and unquoted keys are all fine in a .js file and all invalid under RFC 8259. Remove them, or convert single quotes to double quotes, and the input will parse here and in your code.

Does this JSON validator check against a JSON Schema?

No. It checks that the text is well-formed JSON, which is the question JSON.parse answers. Checking that required fields exist, that a value is an integer, or that an enum has an allowed value needs a JSON Schema validator such as Ajv in your build or test pipeline.

What JSONPath syntax does the query box support?

Queries run through jsonpath-plus, which supports the common Goessner syntax: $ for the root, dot and bracket notation, [*] wildcards, .. recursive descent, array slices like [0:5] and filter expressions such as $.items[?(@.price > 10)]. Results are always returned as a JSON array.

Is the JSON I paste into the formatter uploaded anywhere?

No. Parsing, formatting and querying all happen in your browser tab with JavaScript, and nothing is sent to a server. That makes it reasonable for API responses that contain internal data, although tokens and personal data are still best redacted out of habit.

Should I minify JSON before sending it over HTTP?

It helps a little, but HTTP compression such as gzip or Brotli removes most of the whitespace cost anyway. Minify when size matters in places without compression, such as environment variables, URL parameters, browser storage or database columns with a size limit.

Why did the formatter change a long number in my JSON?

JSON.parse stores numbers as 64-bit floating point, which represents integers exactly only up to 2^53 - 1 (9,007,199,254,740,991). Larger IDs are rounded during parsing, so the beautified output shows a different number. Keep such IDs as strings in your API.

Is there an in-depth guide to the JSON Formatter?

Yes. “JSON Formatting, Validation and JSONPath: A Practical Guide” covers the background, how it works, common pitfalls and worked examples. Read the full guide.