Skip to content

About

Validate JSON against JSON Schema without losing number precision.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

swift-json-schema logo

swift-json-schema

Validate JSON against JSON Schema without losing number precision.

CI Swift 6.3+ Platforms: iOS 18+ | macOS 15+ | Linux License: Apache-2.0 WITH Swift-exception

Overview · Quick look · Install · Usage · Requirements · Documentation · Contributing · License

Overview

Compile a schema once and reuse it for validations with separate evaluation state. Exact decimal checks distinguish 0.3 from 0.30000000000000001 for multipleOf: 0.1; the usage guide covers supported drafts, output formats, and limits.

Quick look

import JSONSchema
import JSONValue

let definition = try JSONValue.parse(#"{"type":"number","multipleOf":0.1}"#)
let validator = try SchemaCompiler().compile(definition)
print(validator.validate(try JSONValue.parse("0.3")).valid)                  // true
print(validator.validate(try JSONValue.parse("0.30000000000000001")).valid)  // false

Install

This is an independent implementation. It shares the SwiftPM package identity swift-json-schema with ajevans99/swift-json-schema, so both repositories cannot appear in the same package dependency graph.

Add the package and the products you need to Package.swift:

dependencies: [
  .package(
    url: "https://github.com/swift-library/swift-json-schema.git",
    .upToNextMinor(from: "0.1.1")
  ),
],
targets: [
  .target(
    name: "YourTarget",
    dependencies: [
      .product(name: "JSONValue", package: "swift-json-schema"),
      .product(name: "JSONSchema", package: "swift-json-schema"),
    ]
  ),
]

Note

swift-json-schema is pre-1.0. Minor releases may include source-breaking changes, so depend on it with .upToNextMinor(from:).

Usage

Choose the JSON value, schema validation, builder, conversion, or Foundation Models product your target needs. The usage guide covers reference resolution, schema construction, CLI commands, locked conformance results, and measured benchmarks.

Requirements

  • Swift 6.3 or later, using Swift 6 language mode. Shared Apple CI uses Xcode 26.6 on macOS 26.
  • iOS 18+ or macOS 15+. CI also configures Linux builds and tests.
  • Foundation Models bridging requires iOS 26+ or macOS 26+ and an SDK that provides Foundation Models. It accepts a representable subset and throws for unsupported shapes or keywords. Validate generated content with the original schema.

Documentation

Contributing

See Contributing for local build, test, formatting, CLI and compliance checks. CI also builds the module DocC catalogs.

License

Apache-2.0 WITH Swift-exception. Vendored test suites retain their licenses beside the test data.

About

Validate JSON against JSON Schema without losing number precision.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages