Bhaskar
Bhaskar

Reputation: 10681

Validate JSON object using a Schema Definition

Just we can validate an incoming XML file based on the pre-defined schema, i.e. XSD or DTD, can we performation a validtaion on an incoming JSON object. Is there any JSON Schema Definition available?

Upvotes: 18

Views: 5875

Answers (5)

Andrew
Andrew

Reputation: 770

OpenAPI is probably the best answer to this now. It's supported in .Net 5.0. This seems to be the industry direction.

Upvotes: 1

peak
peak

Reputation: 116730

http://json-schema.org/implementations.html gives a list of validators.

There are 32 validators listed as of November 2015. One of them is available as an interactive online tool: http://www.jsonschemavalidator.net/

The others are grouped by implementation language.

In many cases, an indication of whether the validator supports the current version of JSON Schema is also given.

Upvotes: 1

oferei
oferei

Reputation: 1828

There's a new library, json-gate, that does the trick. (Full disclosure: I am the author.)

It is similar to JSV and others, but it has several advantages:

  • It is fast*.
  • It produces human-friendly, detailed error messages - for both you and your customers.
  • Friendly, extensive documentation. Not only of the library but of JSON schema as well!
  • The schema is pre-validated. This allows you, the developer, to know right away if your schema definition is malformed. And it makes things run a little faster.

* It is not fast so much as JSV is incredibly slow. My test shows JSV to be 30 (!) times slower than json-gate. This result is consistent with Robert Schultz's tests, which compare JSV against other libraries.

Upvotes: 1

Baggz
Baggz

Reputation: 17423

There are few libraries, which validate data against JSON Schema....

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038790

There's a working draft of a JSON schema. You could also take a look at Cerny.

Upvotes: 10

Related Questions