25

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?

3

3 Answers 3

6

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.

1
  • 3
    I'm betting a lot has changed on this subject since March 2010. What are your thoughts now? Are you using anything for JSON validation? Also, @Fredrik , how about yourself?
    – blong
    Nov 11, 2011 at 20:21
4

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.

3
4

@b.long I came across this post looking for a very particular solution to easily verify if a String's content has a JSON (object/array). I couldn't find any library that would suit my needs.

JSON Tools project or json-schema-validator though offer a lot are too big for my needs. Thus I did implement my own solution that is build on top of JSON.org reference implementation of JSON in Java. I have already been using the JSON.org's code and technically all this functionality was already there, thus I added this very simple functionality reusing its code.

I use it to easily test if the String returned by methods querying my database are formatted in proper JSON which otherwise if badly formatted and posted to a client might cause it to stop working.

Hope this is of use to you as it is to me.

Not the answer you're looking for? Browse other questions tagged or ask your own question.