Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate JSON object using a Schema Definition

Tags:

json

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?

like image 710
Bhaskar Avatar asked Dec 15 '09 08:12

Bhaskar


People also ask

Can we validate JSON with schema?

JSON Schema is a powerful tool. It enables you to validate your JSON structure and make sure it meets the required API. You can create a schema as complex and nested as you need, all you need are the requirements. You can add it to your code as an additional test or in run-time.

How do you validate a JSON file against a schema?

The simplest way to check if JSON is valid is to load the JSON into a JObject or JArray and then use the IsValid(JToken, JsonSchema) method with the JSON Schema. To get validation error messages, use the IsValid(JToken, JsonSchema, IList<String> ) or Validate(JToken, JsonSchema, ValidationEventHandler) overloads.

What is meant by JSON Schema validation?

JSON Schema validation asserts constraints on the structure of instance data. An instance location that satisfies all asserted constraints is then annotated with any keywords that contain non-assertion information, such as descriptive metadata and usage hints.

What is the value of using JSON Schema for validation?

The primary strength of JSON Schema is that it generates clear, human- and machine-readable documentation. It's easy to accurately describe the structure of data in a way that developers can use for automated validation. This makes work easier for developers and testers, but the benefits go beyond productivity.


2 Answers

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

like image 116
Darin Dimitrov Avatar answered Oct 09 '22 12:10

Darin Dimitrov


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

  • Amanda
  • Revalidator
  • JSV
  • Schema.js
like image 38
Baggz Avatar answered Oct 09 '22 11:10

Baggz