Skip to content

Repository files navigation

JSONPatch - Swift 4 json-patch implementation

Apache 2 LicenseSupported PlatformsBuild 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.

Release

1.0 - Feature complete.

Installation

CocoaPods

To use JSONPatch within your project. Add the "RMJSONPatch" into your Podfile:

platform:ios,'8.0'use_frameworks!target'<Your Target Name>'dopod'RMJSONPatch',:git=>'https://github.com/raymccrae/swift-jsonpatch.git'end

Swift Package Manager

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

// swift-tools-version:4.0
import PackageDescription
letpackage=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.
.target(
name:"YourProject",
dependencies:["JSONPatch"]),])

Usage

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

Applying Patches

import JSONPatch
letsourceData=Data(""" {"foo": "bar"}""".utf8)letpatchData=Data(""" [{"op": "add", "path": "/baz", "value": "qux"}]""".utf8)letpatch=try!JSONPatch(data: patchData)letpatched=try! patch.apply(to: sourceData)

Generating Patches

import JSONPatch
letsourceData=Data(""" {"foo": "bar"}""".utf8)lettargetData=Data(""" {"foo": "bar", "baz": "qux"}""".utf8)letpatch=try!JSONPatch(source: sourceData, target: targetData)letpatchData=try! patch.data()

License

Apache License v2.0

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages