ToolForge
How-toJSON

How to Validate JSON

"Is this JSON valid?" is three questions wearing one coat. Is it *well-formed* — does it parse at all? Does it *conform* — are the fields the ones the consumer expects, with the right types? And is it *correct* — is the data actually right?

Only the first is what a JSON validator answers. This covers how to check each level, in a browser and in a pipeline, and where each one stops being useful.

Written by toolforge.websitePublished Last reviewed How we build and check these tools

Three levels of valid

Being precise about this saves real time, because most arguments about whether a payload is "valid" are two people answering different questions.

LevelThe questionWhat checks it
Well-formedDoes it parse?Any JSON parser or validator
ConformingAre the fields and types as agreed?JSON Schema, or your own code
CorrectIs the data right?Tests, review, a human

The gap between the first two is where production incidents live. {"userId": "42", "email": null} is perfectly well-formed JSON. It is also an ID that arrived as a string when your code expects a number, and a null in a field marked required — and no JSON validator on earth will mention either.

RFC 8259 is only about the first level. It defines syntax; ECMA-404 says the same thing about itself in as many words. Nothing in the format has any opinion about which fields your API ought to return.

Checking that a document is well-formed

The quickest check is a parse: if a parser accepts it, it is valid JSON, and if it does not, the error tells you where.

  1. Paste the document into the JSON formatter.

    It parses as you go and reports validity along with the formatted output.

  2. Read the verdict.

    Valid documents are formatted and highlighted; invalid ones produce the parser's own error message plus the line the failing character sits on.

  3. For an invalid document, work from the character position.

    The offset is exact, and the real mistake is usually the token just before the one named.

  4. Check the tree view for structure you did not expect.

    Type labels on each node make it obvious when a number arrived as a string, or an object where you expected an array of them.

Doing it without a browser

Every mainstream language will validate JSON in one line, which is what you want for a file on a server or a step in a build.

Python needs nothing installed:

python -m json.tool file.json

It prints the formatted document on success and the error with a line and column on failure, and returns a non-zero exit status — which is what makes it usable in a script.

jq is the tool worth having if you handle JSON regularly. It validates, and it also streams, so it copes with files far larger than a browser tab will:

jq empty file.json

empty produces no output; the exit status is the answer. In Node, JSON.parse inside a try/catch is the whole story, and in CI a single step that parses every changed .json file will catch a malformed config before it ships. A pre-commit hook doing the same thing catches it before it is even committed.

A caution about that last one: do not build a validation step on a regular expression. JSON is a recursive grammar, so no regex can match it correctly, and a "JSON-ish" pattern will pass documents that no parser accepts. Use a parser; you have one in every language you already have installed.

Validating structure with JSON Schema

Once syntax is settled, the useful question is whether the document has the shape both ends agreed on. That is what JSON Schema is for: a JSON document that describes the permitted shape of other JSON documents — required fields, types, string patterns, numeric ranges, enumerated values, nested object shapes.

A minimal example:

{
  "type": "object",
  "required": ["userId", "email"],
  "properties": {
    "userId": { "type": "integer" },
    "email":  { "type": "string", "format": "email" },
    "tags":   { "type": "array", "items": { "type": "string" } }
  }
}

Validate the earlier payload against that and you get real answers: userId is a string where an integer was required, and email is null where a string was required. Both were invisible to syntax validation.

Where this matters most is at a boundary you do not control — a webhook, a partner's API, a queue consumer. Schema validation at the edge turns "the data was wrong three services deep" into "the request was rejected with a reason".

ToolForge does not do schema validation, and it is worth saying so plainly. The schema visualizer infers the shape of a document you paste — types, nesting, which keys appear — which is genuinely useful for writing a schema or understanding an unfamiliar payload, but its own page is careful to note that it does not produce a formal JSON Schema document and does not validate against one. For actual validation, use a library: Ajv in JavaScript, jsonschema in Python, or whatever your framework already has. If your API is described by OpenAPI, you may have schemas already and not be enforcing them.

Validating what you produce, not just what you receive

Validation gets discussed as a defensive measure against other people's data. Half its value is on the way out.

Three cases where checking your own output pays for itself:

Hand-written configuration. Anything a human edits — a feature-flag file, a seed dataset, a translations bundle — should be parsed by CI on every change. It is one step, and the failure it prevents is a deploy that breaks on startup.

Generated payloads. If you build JSON by string concatenation anywhere, you have a quoting bug waiting to happen: a customer with an apostrophe in their name, or a description containing a newline. Use your language's serialiser rather than templating, and if you must template, escape the values properly.

Fixtures in tests. A malformed fixture produces a test failure that looks like a code bug. Validating fixtures separately makes the difference obvious immediately.

For the specific case of "did this payload change", a validator is the wrong instrument entirely — comparing it structurally against a known-good version answers the question directly, and ignores reordered keys and reformatting while doing so.

What validation will never tell you

Worth being blunt, because "the JSON is valid" gets used as though it settled something.

A well-formed, schema-conforming document can still be wrong in every way that matters. The timestamp can be in the wrong timezone. The amount can be in dollars where the consumer assumes cents. The ID can point at a record that was deleted. The producer can send recipentEmail where the contract said recipientEmail — and schema validation catches that one only if you marked the field required, which is exactly the case people forget.

Two format-level traps validation also misses, both covered in the syntax reference:

Duplicate keys. Legal JSON. Every parser accepts {"a": 1, "a": 2} and most keep the last value, so a document that silently lost half its data validates perfectly.

Numeric precision. A nineteen-digit identifier is a valid JSON number, and it is a rounded number by the time a JavaScript consumer sees it. The document is valid; the value is wrong.

Validation is a floor, not a guarantee. It tells you the message is a message. Whether it says what it should is a question for your tests.

JSON Formatter

Format, validate, and beautify JSON online. It runs in your browser, so the files never leave your machine, and there is nothing to install or sign up for.

Try the JSON Formatter

Frequently asked questions

What is the fastest way to check if JSON is valid?

Parse it. In a browser, paste it into a formatter; on a command line, python -m json.tool or jq empty. All three give a yes-or-no plus an error position, and none of them needs anything installed beyond what you already have.

Is there a JSON validator that checks my fields, not just syntax?

That needs JSON Schema and a schema-aware library — Ajv for JavaScript, jsonschema for Python. ToolForge does not include one; its schema tool infers and displays a document's shape rather than validating against a schema, and its page says so.

Can I validate JSON with a regular expression?

No. JSON is a recursive grammar and regular expressions cannot express recursion, so any pattern will either reject valid documents or accept invalid ones. Every language you have already ships a real parser.

Should I validate JSON on both the client and the server?

Yes, for different reasons. Client-side validation is a fast feedback loop for the person filling in the form. Server-side validation is the one that actually protects anything, because a client can be bypassed entirely. Never treat a client-side check as a security control.

The short version

Parsing tells you a document is well-formed, and that is all it tells you. If a consumer depends on particular fields and types, put a schema at that boundary and enforce it with a real library — and remember that duplicate keys, rounded long integers and a plausible-looking null will all pass every syntax check you run. Validate your own output as well as everyone else's; the config file a human edited is the one most likely to break a deploy.

Tools that go with this

Each one is here for a specific reason rather than because it is in the same category.

JSON Schema Visualizer

Visualize JSON Schema structure and validation

Open Tool

Shows the shape a sample document actually has, which is the first step towards knowing what to validate against.

JSON Parse Tool

Parse JSON strings into JavaScript objects

Open Tool

A quick yes-or-no on whether a string parses, without the formatting apparatus around it.

JSON Diff Comparator

Compare two JSON files and find differences

Open Tool

Answers the question a validator cannot: whether this payload matches the one that was known to be right.

JSON Filter Tool

Filter JSON data by keys and values

Open Tool

Useful for spot-checking that records in a large array really do carry the field you assumed.

Sources

  1. RFC 8259 (STD 90) — The JavaScript Object Notation (JSON) Data Interchange Format

    IETF · Standards organisation · published 1 December 2017 · accessed 7 September 2026

    Cited for: That the standard covers syntax only, plus the duplicate-key and numeric-precision caveats validation cannot catch

  2. ECMA-404, 2nd edition — The JSON Data Interchange Syntax

    Ecma International · Standards organisation · published 1 December 2017 · accessed 7 September 2026

    Cited for: That defining syntax carries no semantics, which is the gap schema validation fills

  3. JSON.parse() — JavaScript reference

    MDN Web Docs · Technical documentation · accessed 7 September 2026

    Cited for: Parsing as the syntax check, and the SyntaxError that reports where it failed

About the author

toolforge.website

Builder and maintainer, ToolForge

Started ToolForge in May 2026 and has built and maintained it since, writing every tool on the site and the documentation that goes with each one.

How we research and check this content · About ToolForge

Part of

JSON

What JSON is, the syntax rules that actually trip people up, why a parser rejected your file, and how JSON compares with XML and YAML.

Browse all developer tools
Buy Me a Coffee