Latest 0.0.2
Homepage https://github.com/krpiatkowski/json-schema-validator
License MIT
Platforms ios 7.0, requires ARC
Authors ,

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)

Latest podspec

{
    "name": "json-schema-validator",
    "version": "0.0.2",
    "summary": "A json schema validator for iOS",
    "description": "json-schema-validator is iOS implementation the json-schema draft found at http://json-schema.org",
    "homepage": "https://github.com/krpiatkowski/json-schema-validator",
    "license": "MIT",
    "authors": {
        "krpiatkowski": "[email protected]",
        "CodeReaper": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/krpiatkowski/json-schema-validator.git",
        "tag": "0.0.2"
    },
    "source_files": "json-schema-validator/Classes/**/*.{h,m}",
    "resources": [
        "json-schema-validator/Resources/*.json"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This