A json schema validator for iOS based on http://json-schema.org
The classes can be added to your project by including /json-schema-validator/Classes/* and /json-schema-validator/Resources/*
or even easier just install it as a CocoaPod.
NSError *errors = [[TFJSONSchemaValidator validator] validate:json withSchema:@"someSchema"]
The parameter json is a NSDictionary representation of the json string, created by using NSJSONSerializer.
If reading up or parsing the schema fails errors will be a NSJSONSerializer error. Otherwise errors.userInfo[@"errors"] is a array with all the validations errors
Any schema provided is validated against the Core/Validation schema
Of a object has more then on of the following: type, enum, $ref, allOf, anyOf, not
The validation fails with a prefixed with "schema-error"
The reason for this is that the specification does not mention what happens if more then one of the keywords is found.
What does the following mean?
{
"allOf" : [{"type" : "string"}],
"anyOf" : [{"type" : "number"}, {"type" : "null"}]
}
Regular expression engine and syntax is not ecma262, instead ICU is used.
The reason for this is that ICU is the engine build into Objective-C and makes parsing and running expressions alot simpler.
$ref's can reference to a schema in the same NSBundle specified in the constructor (default is [NSBundle mainBundle]). Schemas are refereced like this: bundle://filename.json
- multipleOf
- exclusiveMaximum
- exclusiveMinimum
- format
- uniqueItems
- maxProperties
- minProperties
- additionalProperties
- dependencies
- not
- definitions (only external and any definitions below root level are missing)