JSONPatch is a Swift library that implements JSON Patch RFC6902. JSONPatch uses JSONSerialization from Foundation, and has no dependencies on third-party libraries.
The implementation uses the JSON Patch Tests project for unit tests to validate its correctness.
Use Swift 6.0 or later. Apple development requires Xcode 16 or later. The library supports macOS 10.15+, iOS 13+, tvOS 13+, watchOS 6+, and Linux. Tests run on macOS 14+ or iOS/tvOS 17+ hosts; these test requirements do not change the library's deployment targets.
Version 2.0.0 introduces the Swift 6 migration. See the migration guide for the breaking error-payload change and the changelog for release notes. Version 1.0.6 added Linux support.
Use Swift Package Manager for new integrations and future releases.
See the Swift Package Manager installation guide for Xcode and Package.swift instructions.
Existing CocoaPods users can install version 2.0 directly from the v2.0.0 Git tag.
This bypasses public Trunk, which is scheduled to become read-only on December 2, 2026.
See the CocoaPods installation guide for the Podfile configuration and guidance for users staying on version 1.x.
See Carthage.md
A more detailed explanation of JSONPatch is given in Usage.md.
import JSONPatch
let sourceData = Data("""
{"foo": "bar"}
""".utf8)
let patchData = Data("""
[{"op": "add", "path": "/baz", "value": "qux"}]
""".utf8)
let patch = try! JSONPatch(data: patchData)
let patched = try! patch.apply(to: sourceData)import JSONPatch
let sourceData = Data("""
{"foo": "bar"}
""".utf8)
let targetData = Data("""
{"foo": "bar", "baz": "qux"}
""".utf8)
let patch = try! JSONPatch(source: sourceData, target: targetData)
let patchData = try! patch.data()JSONPointer, JSONPatch.ApplyOption, and JSONError can cross actor boundaries.
Keep JSONPatch, its operations, and JSONElement within one actor or task because they can retain mutable Foundation objects.
Transfer JSON Data between actors and create the patch inside the receiving actor.
See the concurrency example.
Swift Testing is supplied by the toolchain. Run both configurations with compiler warnings treated as errors:
swift test -Xswiftc -warnings-as-errors
swift test --configuration release -Xswiftc -warnings-as-errorsOn macOS, validate the standalone project and framework builds:
bash Scripts/check-apple.sh tests
bash Scripts/check-apple.sh frameworks
pod lib lint RMJSONPatch.podspec --fail-fast
carthage build --no-skip-current --use-xcframeworks --platform iOS,macOS,tvOS,watchOS
python3 Scripts/check-xcframework.py Carthage/Build/JSONPatch.xcframework ios macos tvos watchosThe Xcode test check requires an installed iPhone simulator runtime. CocoaPods and Carthage must be installed for their respective checks. GitHub Actions runs Swift 6.0 and 6.2 tests on macOS and Linux, plus Apple distribution checks.
Apache License v2.0