Code Monkey home page Code Monkey logo

swift-jsonpatch's Introduction

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.

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>' do
    pod '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

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.
        .target(
            name: "YourProject",
            dependencies: ["JSONPatch"]),
    ]
)

Carthage

To use JSONPatch within your project, specify it in your Cartfile:

github "raymccrae/swift-jsonpatch" "v1.0.1"

Usage

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

Applying Patches

import JSONPatch

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

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

Generating Patches

import JSONPatch

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

License

Apache License v2.0

swift-jsonpatch's People

Contributors

cassianodialpad avatar raymccrae avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.