Skip to content

krpiatkowski/json-schema-validator

Repository files navigation

json-schema-validator

A json schema validator for iOS based on http://json-schema.org

Installing

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.

Usage

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

Deviations from specification

instance type validation

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 expressions

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.

Bundle

$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

Missing from implementation

Numeric

  • multipleOf
  • exclusiveMaximum
  • exclusiveMinimum

String

  • format

array

  • uniqueItems

objects

  • maxProperties
  • minProperties
  • additionalProperties
  • dependencies

instance type

  • not
  • definitions (only external and any definitions below root level are missing)

About

A json schema validator for iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published