JSONPatchSwift is an implementation of JSONPatch (RFC 6902) in pure Swift. It uses SwiftyJSON for JSON handling.
You can use CocoaPods to install JSONPatchSwift
by adding it to your Podfile
:
platform :ios, '9.0'
use_frameworks!
target 'MyApp' do
pod 'JSONPatchSwift', :git => 'https://github.com/EXXETA/JSONPatchSwift.git'
end
Note that this requires CocoaPods version 36, and your iOS deployment target to be at least 9.0:
import JSONPatchSwift
Using a String:
let jsonPatch = try? JPSJsonPatch("{ \"op\": \"add\", \"path\": \"/baz\", \"value\": \"qux\" }")
Or using a SwiftyJSON object:
let json = JSON(data: " { \"op\": \"add\", \"path\": \"/baz\", \"value\": \"qux\" } ".dataUsingEncoding(NSUTF8StringEncoding)!)
let jsonPatch = try? JPSJsonPatch(json)
let json = JSON(data: " { \"foo\" : \"bar\" } ".dataUsingEncoding(NSUTF8StringEncoding)!)
let resultingJson = try? JPSJsonPatcher.applyPatch(jsonPatch, toJson: json)
The framework supports all operations described by RFC 6902. Until we (or you? - see "contributing") find the time to add a documentation for each operation, we kindly ask to use our extensive test suite to find examples:
- add operation: JPSAddOperationTests.swift
- copy operation: JPSCopyOperationTests.swift
- move operation: JPSMoveOperationTests.swift
- remove operation: JPSRemoveOperationTests.swift
- replace operation: JPSReplaceOperationTests.swift
- test operation: JPSTestOperationTests.swift
- iOS 9.0+
- Xcode 7
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
- v1.2 - upgrade to 100% documented and 100% tested
- v1.1 - fixed a packaging problem
- v1.0 - initial release
- EXXETA AG
- See Contributors
Apache License v2.0