JSONSchema.swift:简单、易用的 JSON Schema 校验器类库

1,396 阅读1分钟
原文链接: github.com

Build Status

An implementation of JSON Schema in Swift.

Installation

Usage

import JSONSchema

let schema = Schema([
    "type": "object",
    "properties": [
        "name": ["type": "string"],
        "price": ["type": "number"],
    ],
    "required": ["name"],
])

schema.validate(["name": "Eggs", "price": 34.99])

Error handling

Validate returns an enumeration ValidationResult which contains all validation errors.

println(schema.validate(["price": 34.99]).errors)
>>> "Required property 'name' is missing."

JSONSchema has full support for the draft4 of the specification. It does not yet support remote referencing #9.

License

JSONSchema is licensed under the BSD license. See LICENSE for more info.