Validate JSON against JSON Schema without losing number precision.
Overview · Quick look · Install · Usage · Requirements · Documentation · Contributing · License
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.
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) // falseThis 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:).
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.
- 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.
- Usage guide: examples, behavior, and limits.
- JSON values and exact serialization
- Schema compilation and validation
- Schema builders and macros
- Foundation conversions
- Foundation Models bridge
- Release: release facts and mechanics; version rules are in VERSIONING.
See Contributing for local build, test, formatting, CLI and compliance checks. CI also builds the module DocC catalogs.
Apache-2.0 WITH Swift-exception. Vendored test suites retain their licenses beside the test data.