JSON Editor FreeOpen the JSON editor

Docs/JSON Schema

JSON validator with JSON Schema

A JSON validator that works as you edit: give a panel a JSON Schema and JSON Editor Free checks the document against it, marking each value that breaks a rule.

Updated

Open this page in the editor

Check a document

  1. Press the Schema button in the panel’s toolbar, or press Ctrl+Alt+V.
  2. Paste the schema, open it from a file, or fetch it from an address.
  3. Press Apply schema. The status bar counts the errors, and each one shows at its value.
  4. Fix a value and its error clears a moment later. Remove schema stops checking.

Keys

JSON SchemaCtrl+Alt+V
Go to the next errorF8
Every shortcut

Validate JSON: an example

To validate JSON, paste it into a panel or open a file. JSON Editor Free works as a JSON validator as you type: broken syntax is underlined at once, with no schema needed. To check the data itself, press Schema, paste a JSON Schema and press Apply schema.

For example, check the document {"planet": "Mars", "moons": 2.5} against the schema {"type": "object", "required": ["name"], "properties": {"moons": {"type": "integer"}}}. The editor reports two errors, each at its value: “The document is missing the required key name.” and “moons must be a whole number. Found the number 2.5.”

Validate a JSON array against a schema

Much of the JSON people check is a list: an API response, an export, a set of config entries. In a JSON Schema, items gives the rule every item of an array must follow.

For example, the schema {"type": "array", "items": {"type": "object", "required": ["id", "status"], "properties": {"id": {"type": "integer"}, "status": {"enum": ["open", "closed"]}}}} says each item is an object with a whole-number id and a status of open or closed. Check the array [{"id": 1, "status": "open"}, {"id": "2", "status": "done"}, {"id": 3}] against it and the editor reports three errors, each at the item that has it: “id must be a whole number. Found the string "2".”, “status must be one of the allowed values. Found the string "done".” and “2 is missing the required key status.”

Items count from 0, so “2” is the third item. Fix a value and its error clears a moment later. To see which items changed between two versions of a list, use JSON diff: compare two JSON files; to put the items in order first, see Sort JSON keys and arrays.

Validate JSON syntax, then its structure

There are two checks. Syntax: in text mode, JSON Editor Free checks that the text is valid JSON as you type, with no schema needed. Invalid JSON is underlined and the status bar shows the line, the column and what is wrong; see JSON viewer: tree, table and text.

Structure: valid JSON can still have the wrong keys or types. A JSON Schema describes what the data must hold, and the editor checks every value against it.

If the text is almost JSON, such as a trailing comma, single quotes or comments, Repair fixes it in one step; see JSON formatter and JSON repair.

What a schema can check

  • type: a value must be a string, a number, a whole number, true or false, an array, an object or null.
  • required: the keys an object must have.
  • enum and const: the only values allowed.
  • minimum, maximum, minLength, maxLength and pattern: ranges, lengths and text patterns.
  • additionalProperties: whether keys the schema does not name are allowed.
  • For example, {"type": "object", "required": ["name"], "properties": {"moons": {"type": "integer"}}} reports a missing name and a moons value that is not a whole number.

Supported drafts

JSON Editor Free validates JSON Schema draft-07, 2019-09 and 2020-12. It reads the draft from the schema’s $schema keyword; a schema without $schema is checked as draft-07, and an unknown one is checked as draft-07 with a notice.

Remote $ref addresses are not fetched, so a schema must be complete on its own.

The document is checked against the schema in your browser; checking sends nothing to a server.

Where errors show

In tree mode the row gets a short red label, such as “must be a whole number”, and the value is underlined. In text mode the value is underlined and the full message sits in the gutter, for example “moons must be a whole number. Found the string "2".”

A missing required key is reported on the object that should hold it. F8 goes to the next error.

PreviousOpen, save and CSVNextLarge documents