开发者

Validate JSON object using a Schema Definition

开发者 https://www.devze.com 2022-12-13 21:24 出处:网络
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 Definit

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?


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


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

  • Amanda
  • Revalidator
  • JSV
  • Schema.js


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消