Question

I have JSON returned from a server, and I would like to validate it against a JSON Schema (probably draft V3, can change though).

I thought that perhaps NSDictionary would have the functionality, but it doesn't seem to, here is my attempt:

[self.dictionary ]

(where dictionary is an NSDictionary)

There weren't any methods for validating the NSDictionary against a JSON schema that I could find. How do I do this?

Please note that you can write C and C++ in objective-c, hence these tags being present in the question.

Was it helpful?

Solution 2

After not finding a satisfactory answer to this question - I went away and developed my own schema validator in native Objective-c here: https://github.com/samskiter/KiteJSONValidator

I've just got it passing all the tests in the JSON-Schema test suite so I've released v0.1.

It's released under the MIT license so I hope it's useful to someone...

OTHER TIPS

Objective-C is a superset of C. JSON Schema site lists a C library wjelement, you can adapt it.

The example function call is

WJESchemaValidate(schema, json, schema_error, schema_load, NULL, format)

You'll need to supply a C string, rather than NSString, naturally.

Note: after I wrote the answer, I realised you were fine with pure C from the start :)

For anyone who is looking for an MIT licensed JSON schema validator, "JsonSchemaValidator" does a nice job and is available here: https://bitbucket.org/nut_code_monkey/jsonschemavalidator

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top