# Online JSON5 Schema Validator: JSON Schema | JSON5.dev


Source: https://json5.dev/tools/online-schema-validator/

---

# Online Schema Validator: JSON5

Check a JSON5 document against a JSON Schema, in your browser.

A syntax check tells you a file parses. It does not tell you the port is a number, the name is present, or the region list holds only strings. JSON Schema describes those rules, and it works on JSON5 because a schema validates the parsed value, not the text.

Paste a document on the left and a schema on the right. Both boxes accept JSON5, so the schema itself can have comments and unquoted keys. Each failed rule is listed with the path of the value that broke it. Everything runs locally and nothing is uploaded.

![A JSON5 document checked against a JSON Schema, with one field flagged as the wrong type](https://json5.dev/img/hero/tools-online-schema-validator.png)

**TL;DR:** Document on the left, JSON Schema on the right, both parsed as JSON5. Pick the draft your schema was written for (2020-12 by default). A green result means the document matches. A red result lists each rule that failed and where.

## Validate JSON5 Against a JSON Schema

A sample document and schema are loaded. The document breaks three rules: a port out of range, a number in a list of strings, and a missing required key.

Schema draft 

JSON5 document 

JSON Schema 

  

**Private by design:** the document and the schema are parsed and checked in your browser. They are never uploaded, logged or sent to any server, and they are gone when you close the tab. Open file and drag and drop read the file inside your browser. Copy link puts both texts in the part of the address after the # sign, which browsers do not send to any server.

![Settings icon](https://json5.dev/images/icons/settings.png)

## How It Works

[JSON Schema](https://json5.dev/glossary/#json-schema) is defined over JSON values: objects, arrays, strings, numbers, booleans and null. It has nothing to say about how those values were written down. So the tool does two separate things.

1.  **Parse.** The document and the schema are each read by the reference JSON5 parser. Comments disappear, `0x1F90` becomes the number 8080, and unquoted keys become ordinary keys. A syntax error stops here and is reported with its box, line and column.
2.  **Validate.** The parsed document is checked against the parsed schema by `@cfworker/json-schema`, an open source validator (MIT license) that is bundled into this page.

Each message in the result has three parts: the keyword that failed (such as `required`, `type` or `maximum`), the path of the value in the document, and a sentence describing the failure. The path uses JSON Pointer form, so `/regions/1` is the second item of `regions`.

When a nested value fails, the validator also reports the parent keyword that contains it. A wrong type for `port` produces a `type` message for `/port` and a `properties` message for the object above it. Read the most specific message first.

![Code icon](https://json5.dev/images/icons/code.png)

## Worked Example

The sample schema is written as JSON5, which keeps it short and lets it carry comments:

`{ // JSON Schema, written as JSON5 type: 'object', required: ['name', 'port', 'owner'], properties: { name: { type: 'string', minLength: 1 }, port: { type: 'integer', minimum: 1, maximum: 65535 }, regions: { type: 'array', items: { type: 'string' } }, owner: { type: 'string' }, }, }`

The sample document is valid JSON5 but breaks three of those rules:

`{ // a service config name: 'orders-api', port: 99999, regions: ['us-east', 42,], }`

-   `owner` is required and missing.
-   `port` is 99999, above the maximum of 65535.
-   `regions[1]` is the number 42, and every item must be a string.

Fix the three values in the left box and the result turns green as you type. The [syntax validator](https://json5.dev/tools/online-validator/) would have accepted this document from the start, which is the difference between the two tools.

![Warning icon](https://json5.dev/images/icons/warning.png)

## Limits to Know

-   **Drafts.** The validator supports drafts 4, 7, 2019-09 and 2020-12. Choose the one your schema names in `$schema`; the tool does not switch for you.
-   **No remote references.** A `$ref` to another URL is not fetched, because this page makes no network requests with your data. References inside the same schema (`#/$defs/...`) work. Paste a bundled schema if yours is split over files.
-   **Infinity and NaN.** JSON5 allows them and JSON Schema was not written with them in mind. They are numbers to the validator, so `type: 'number'` accepts them. Add your own rule if they must be rejected.
-   **Formats.** The `format` keyword (`date-time`, `uri` and so on) is checked for the common formats the library knows. Treat a format pass as a hint, not a guarantee.
-   **Positions.** Messages point at a path in the data, not a line in the text. Use the path to find the value.

To run the same check in a build or a test, parse the file with a JSON5 library and pass the value to a schema validator for your language. The [schema validation tutorial](https://json5.dev/tutorials/schema-validation/) has working examples, and the [VS Code guide](https://json5.dev/tools/vscode/) covers validation while you type.

## FAQ

### Can JSON Schema validate a JSON5 file?

Yes. JSON Schema validates values, not text. Parse the JSON5 file first and validate the result. That is what this tool does.

### Is there a separate schema language for JSON5?

No. The JSON5 data model is the JSON data model plus `Infinity` and `NaN`, so JSON Schema covers it. Comments are not data and cannot be described by a schema.

### Can I write the schema itself in JSON5?

In this tool, yes: the schema box accepts JSON5 and JSON. In other tools it depends on whether they parse the schema file with a JSON5 parser. Most expect a strict JSON schema file.

### Why do I see a message for "properties" as well as the real error?

The validator reports each keyword on the way down to the failing value. The `properties` line says a property below it failed; the more specific line that follows says which one and why.

### Is my document or schema uploaded?

No. Both stay in your browser tab. Nothing is transmitted or stored, and remote references are never fetched.

## See Also

[

### Schema Validation Tutorial

The same check in code and CI

](https://json5.dev/tutorials/schema-validation/)[

### Online Validator

Syntax only, with line numbers

](https://json5.dev/tools/online-validator/)[

### Data Types

What a schema can describe

](https://json5.dev/spec/data-types/)

## More Online Tools

Compare two files by their data, or fix one that will not parse.

[Online Diff](https://json5.dev/tools/online-diff/) [Online Repair](https://json5.dev/tools/online-repair/)
