Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON schema validation using java [closed]

Tags:

I'm writing some acceptance tests for a java webapp that returns JSON objects. I would like to verify that the JSON returned validates against a schema. Can anyone suggest any tools for this?

like image 626
tomdee Avatar asked Mar 23 '10 10:03

tomdee


People also ask

How do I check if a JSON Schema is valid?

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 JSON Schema validation in Java?

JSON Schema Validation: The JSON Schema Validation specification is the document that defines the valid ways to define validation constraints. This document also defines a set of keywords that can be used to specify validations for a JSON API.


2 Answers

The JSON Tools project (Programmer's Guide) includes a tool to validate the contents of a JSON file using a JSON schema.

An alternative could be to validate running the (JavaScript) JSON Schema Validator using Rhino.

like image 190
Simon Lieschke Avatar answered Dec 05 '22 00:12

Simon Lieschke


The json-schema-validator (currently in version 0.0.1, so it's in a pre-alpha state) worked pretty well for me. Be aware that it is not 100% feature complete but it could still correctly identify a lot of errors in my json content.

like image 24
Fredrik Avatar answered Dec 04 '22 23:12

Fredrik