Swiftpack.co - Package - raymccrae/swift-jsonpatch

JSONPatch - Swift 4 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.


0.3 - Cocoapods support.


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()


Swift Package Manager

Add JSONPatch as a dependency to your projects Package.swift. For example: -

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "YourProject",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/raymccrae/swift-jsonpatch.git", .branch("master"))
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
            name: "YourProject",
            dependencies: ["JSONPatch"]),


Apache License v2.0


Stars: 1
Help us keep the lights on


Used By

Total: 0


v0.2 - Dec 2, 2018

v0.1 - Nov 17, 2018

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