Swiftpack.co -  kylef/JSONSchema.swift as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
JSON Schema validator in Swift
.package(url: "https://github.com/kylef/JSONSchema.swift.git", from: "0.6.0")

JSON Schema

An implementation of JSON Schema in Swift. Supporting JSON Schema Draft 4, 6, 7, 2019-09, 2020-12.

The JSON Schema 2019-09 and 2020-12 support are incomplete and have gaps with some of the newer keywords.

JSONSchema.swift does not support remote referencing #9.


JSONSchema can be installed via CocoaPods.

pod 'JSONSchema'


import JSONSchema

try JSONSchema.validate(["name": "Eggs", "price": 34.99], schema: [
  "type": "object",
  "properties": [
    "name": ["type": "string"],
    "price": ["type": "number"],
  "required": ["name"],

Error handling

Validate returns an enumeration ValidationResult which contains all validation errors.

print(try validate(["price": 34.99], schema: ["required": ["name"]]).errors)
>>> "Required property 'name' is missing."


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


Stars: 232
Last commit: Yesterday

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

18 weeks ago

Breaking Changes

  • The validation API may now throw errors if the provided JSON Schema is invalid.

  • The structure of ValidationError has changed to include further information such as the location of the failing instance. ValidationError was previous a String.


  • The failing required validation error message is now emitted for each individual required validation failure.

    The following JSON Schema would emit two validation failures, one for missing property name and the other for missing property price when when an empty object was validated.

      "required": ["name", "price"]
  • Support for the minContains and maxContains keywords in JSON Schema draft 2019-09.

  • Support for the uuid format in JSON Schema draft 2019-09.

Bug Fixes

  • The failing required validation error message incorrectly specified other found keys were missing under the case where another missing key validation failed. #61

  • Fixed const and enum comparisons where numbers inside collection types wouldn't be compared correctly (and thus [true] would have been treated as equal to [1].

  • Fixed uniqueItems so that numbers and booleans are not treated equal when found within a collection type (for example unique arrays or objects).

  • The ipv6 format will no longer allow IPv6 addresses containing a zone id.

  • Zero terminates floats such as 1.0 will now validate against the integer type.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API