Latest 1.0.1
License MIT
Platforms ios 9.0, osx 10.10


CocoaPods Compatible
Carthage Compatible
MIT Licence

A Swift μ-framework for creating RFC6902 compliant JSON patch objects


  • iOS 8.0+ / macOS 10.10+
  • Swift 4.2+


The framework relies on the Objective C runtime for converting keypaths into strings, and so it is crucial that the properties the keypaths point to are representable in Objective C. To achieve this, you will have to add the @objc annotation at each variable declaration.

class Patch: NSObject {
    @objc var baz: String!
    @objc var foo: String!
    @objc var hello: [String]!



To integrate JSONPatch into your Xcode project using Carthage, specify it in your Cartfile:

github "peterringset/JSONPatch" ~> 1.0


To integrate JSONPatch into your Xcode project using CocoaPods, specify it in your Podfile:

source ''
platform :ios, '8.0'

target '<Your Target Name>' do
    pod 'PRJSONPatch', '~> 1.0'


Create JSON patch objects using keypath’s in Swift:

import JSONPatch

let stringChanges: [JSONPatch<Patch, String>] = [
    .replace(.baz, value: "boo"),
let arrayChanges: [JSONPatch<Patch, [String]>] = [
    .add(.hello, value: ["world"])

Then, once you’ve created a collection of changes you can use JSONEncoder to convert it to json data:

let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted

let data = try! encoder.encode(changes)
print(String(data: data, encoding: .utf8)!)

This will print the following json:

    "op" : "replace",
    "path" : "/baz",
    "value" : "boo"
    "op" : "remove",
    "path" : "/foo"
    "op" : "add",
    "path" : "/hello",
    "value" : [

JSONPatch supports all the verbs specified in RFC6902, add, remove, replace, move, copy and test.

Latest podspec

    "name": "PRJSONPatch",
    "version": "1.0.1",
    "summary": "A Swift u03bc-framework for creating RFC6902-compliant JSON patch objects",
    "description": "A Swift u00b5-framework for creating RFC6902-compliant JSON patch objects.nnThe framework uses the built in Codable protocol to convert from Swift enum to json objects.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "peterringset": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.0.1"
    "source_files": [
    "swift_versions": "4.2",
    "platforms": {
        "ios": "9.0",
        "osx": "10.10"

Pin It on Pinterest

Share This