Utvikling · verktøy

JSON Schema-validator

Lim inn en JSON-verdi og et JSON Schema. Begge kontrolleres lokalt i nettleseren din.

Kjøres i nettleseren. Ingen opplasting.

Values are processed locally in this browser.

Result

—

Om verktøyet

JSON Schema-validator sem complicação.

Valider dataene og selve skjemaet med draft-07 eller 2020-12. Lokale referanser, kjente formater og unikhetskontroller kjøres i en nettleserprosess som kan avbrytes. Eksterne skjemaer lastes ikke ned. Svært trege uttrykk stoppes for å holde siden brukbar. Store numeriske identifikatorer som overskrider nettleserens nøyaktighet, avvises; bruk tekststrenger for slike identifikatorer.

Veiledning

Slik bruker du JSON Schema-validator

The JSON Schema Validator checks a JSON value against a JSON Schema written for draft-07 or draft 2020-12. It first checks that the schema itself is valid, then lists each place where your data breaks it, with a path and a short reason. Local references and common formats are supported. It does not download remote schemas and it does not fix your data.

Slik gjør du

  1. Paste the JSON value you want to test into the JSON data box. It can be an object, a list or a single value.
  2. Paste your schema into the JSON Schema box. Add a $schema line for draft-07 or draft 2020-12. Without that line the tool uses draft-07.
  3. Press Calculate. A result starting with Valid means the data matches. A result starting with Invalid lists each problem with a path such as #/age and a keyword.
  4. Change the data or the schema and press Calculate again. Copy result copies the list, and Clear empties both boxes.

Eksempler

Data that matches

Du skriver inn
JSON-data
{"name":"Ada","age":36}
JSON Schema
{"type":"object","required":["name","age"],"properties":{"name":{"type":"string","minLength":1},"age":{"type":"integer","minimum":0}},"additionalProperties":false}
Du får
Resultat
Valid · JSON matches the schema (draft 7; known formats checked).

Both required fields are present, the name is not empty, the age is a whole number of at least zero, and there are no extra properties. No $schema line was given, so draft 7 is used.

Kjørt med verktøyets egen kode.

Several problems at once

Du skriver inn
JSON-data
{"name":"","age":-1,"x":1}
JSON Schema
same schema as above
Du får
Resultat
Invalid · 6 issues #: properties: Property "name" does not match schema. #/name: minLength: String is too short (0 < 1). #: properties: Property "age" does not match schema. #/age: minimum: -1 is less than 0. #: additionalProperties: Property "x" does not match additional properties schema. (additional property is not allowed) #/x: false: False boolean schema.

There are three real mistakes: an empty name, a negative age and an extra property x. The count says 6 because each mistake is listed twice, once as a summary line at the parent path and once at the exact path.

Kjørt med verktøyets egen kode.

A required field is missing

Du skriver inn
JSON-data
{"name":"Ada"}
JSON Schema
same schema as above
Du får
Resultat
Invalid · 1 issues #: required: Instance does not have required property "age".

The path # means the whole value. The tool writes 1 issues even for one problem, so do not read the plural as a second error.

Kjørt med verktøyets egen kode.

A reference to a remote schema

Du skriver inn
JSON-data
{"a":1}
JSON Schema
{"$ref":"https://example.com/x.json"}
Du får
Melding
JSON Schema: Unresolved $ref "https://example.com/x.json".

The tool never downloads schemas from the web. A reference it cannot find inside your own schema stops the check with a message like this, which also adds a short list of known schemas. Put the needed parts in $defs or definitions.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Check that a sample API response or a config file follows the schema your team agreed on.
  • Test a new schema against one good and one bad example before you put it in a project.
  • Find out which field breaks a rule when a larger validator only says that something failed.
  • Learn how keywords such as required, minimum, format and uniqueItems behave by trying small inputs.

Begrensninger

  • Only draft-07 and draft 2020-12 are accepted. A schema that names another draft, such as draft-04, is refused with a message about supported drafts.
  • References must point inside the schema you paste. Remote schemas are not downloaded, and a reference that cannot be resolved stops the check.
  • Whole numbers that cannot be held exactly in the browser, such as 9007199254740993, are rejected in the data and the schema. Write large identifiers as strings.
  • A format name the tool does not know gives an error instead of being skipped, and a check that runs too long is stopped after a few seconds to keep the page usable.

Tips

  • Read the lines with deeper paths, like #/age, first. The lines at # only repeat that something below them failed.
  • Always add a $schema line, so the draft is stated and you do not rely on the default of draft-07.
  • Try a data sample that is clearly valid and one that is clearly broken. If both give the same result, the schema is too loose or too strict.

Kilder

Vanlige spørsmål

Sobre JSON Schema-validator.

Which JSON Schema draft does the validator use?

It reads the $schema line of your schema and supports draft-07 and draft 2020-12. If there is no $schema line, it uses draft-07 and says so in the result. A schema that names any other draft is refused.

Does it check the schema itself?

Yes. Before the data is tested, the schema is checked against the official meta-schema of its draft. A mistake such as an unknown type name stops the run and the message says the schema is invalid.

Are formats such as email or date-time checked?

Known formats are checked. A value like not-an-email fails the email format. A format name the tool does not recognise causes an error rather than being ignored, so remove or change it.

Why does it report more issues than I have mistakes?

Each failure is listed at its own path and again as a summary at the parent. In the example above, three real mistakes give six lines. Start with the lines that have the longest paths.

Can it use schemas from a URL?

No. Remote schemas are not downloaded, so the tool works without any network request. Local references inside your pasted schema, for example to $defs, do work.

Is my data uploaded?

No. The check runs inside your browser in a background worker, and neither the data nor the schema is sent to a server.

Why is a very large number refused?

Browsers keep whole numbers exactly only up to a limit. A number past it would be silently rounded, which could give a wrong result, so the tool rejects it. Put such identifiers in quotes and use a string type.

Hvordan bruker du JSON Schema-validator?

Lim inn en JSON-verdi og et JSON Schema. Begge kontrolleres lokalt i nettleseren din.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.