Swiftpack.co - Package - raymccrae/swift-jsonpatch

JSONPatch - Swift 4/5 json-patch implementation

Apache 2 License Supported Platforms Build System

JSONPatch is a a swift module 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.


1.0.4 - Fix bug that raised an Objective-C exception when copying a json element with a NSNumber.



See CocoaPods.md

Swift Package Manager

See SPM.md


See Carthage.md


A more detailed explanation of JSONPatch is given in Usage.md.

Applying Patches

import JSONPatch

let sourceData = Data("""
                      {"foo": "bar"}
let patchData = Data("""
                     [{"op": "add", "path": "/baz", "value": "qux"}]

let patch = try! JSONPatch(data: patchData)
let patched = try! patch.apply(to: sourceData)

Generating Patches

import JSONPatch

let sourceData = Data("""
                      {"foo": "bar"}
let targetData = Data("""
                      {"foo": "bar", "baz": "qux"}
let patch = try! JSONPatch(source: sourceData, target: targetData)
let patchData = try! patch.data()


Apache License v2.0


Stars: 5


Used By

Total: 0


Bugfix Release - 2020-04-02 15:30:12

Thanks to Michiel Horvers for reporting and fixing a bug.


  • If an attempt is made to copy a JSONElement with a raw type of NSNUmber then an Objective-C exception is raised.

Add Apply Options - 2020-03-09 20:18:57

  • Adds Apply Options to unify the mechanism to control how json patches are applied this replaces the additional parameters on the apply methods. This will be a more scalable mechanism for future options.
  • Adds option to ignore non existence references when applying patches.

Thanks to Michiel Horvers michiel@mhcp-software.nl for his contributions

Swift 5 - 2019-10-07 21:02:02

  • A small release to fix the deprecate warning for Swift 5.
  • Documentation updated with steps to use SPM integration within Xcode 11.

Carthage Support - 2019-08-26 17:58:37

Added support for Carthage.

Thanks to Cassiano Monteiro (cassianodialpad) for his contribution.

Feature Complete - 2019-01-04 09:02:28

The first fully feature complete release.

Generate Patch & API Refinement - 2018-12-02 18:43:03

Initial Release - 2018-11-17 15:22:32

  • New Project
  • json-patch implementation in Swift 4 to apply patches
  • 100% passes JSON Patch Tests