views:

546

answers:

2

Are there simple libraries out there (.NET and Java) that are able to validate a JSON string given a schema definition?

It should work similar to how XML can be validated using XSD.

EDIT: I need .NET and Java libraries. Thanks to darin for the .NET link!

+2  A: 

Here You can find some Java classes which might helpful when working with JSON.

When syntax of Your JSON String is incorrect instance of JSONException will be thrown - this is the simplest way to check correctness, I think. JSONTokener is the class You have to use to parse. It has a constructor which takes java.lang.String as a parameter.

Edit: Sorry, I misunderstood a little. Probably JSON Tools is the library You are looking for. It provides validation using a JSON schema.

Dejw
I'm looking for schema validation, not syntax validation. I'll make the question clearer.
Kevin Thiart
I've edited my answer.
Dejw
Upvoted, thanks for the link. I'll be using Json.NET and JSON Tools.No way to accept 2 answers?
Kevin Thiart
+4  A: 

For .NET you could use Json.NET which supports schema validation.

Darin Dimitrov