2017 © Pedro Peláez
 

library jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

image

victuxbb/jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  • Friday, January 16, 2015
  • by victuxbb
  • Repository
  • 4 Watchers
  • 6 Stars
  • 4,422 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 49 % Grown

The README.md

jsonpatch

SensioLabsInsight, (*1)

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902) in PHP, (*2)

Installation

Require victuxbb/jsonpatch into your composer.json file:, (*3)

``` json { "require": { "victuxbb/jsonpatch": "@stable" } }, (*4)

or inside your root project directory

``` bash

$ composer require victuxbb/jsonpatch @stable

Documentation

With a target JSON like this: ``` php $targetJSON ='{"baz": "qux","foo": "bar"}';, (*5)

and a variable with a JSON string operations:
``` php
$patchOperations = '[
     { "op": "replace", "path": "/baz", "value": "boo" }
   ]';

create a instance of Patcher and use the "patch" method to get the json result:, (*6)

``` php $patcher = new Patcher(); $result = $patcher->patch($targetJSON,$patchOperations);, (*7)

$result will contain:
``` json
{"baz":"boo","foo":"bar"}

A typical use case with FOSRestBundle and JMSSerializer: ``` php public function patchUserAction(Request $request,User $user) {
$json = $request->getContent(); $jps = $this->get('json_patch_service'); //symfony service that loads Patcher.php $serializer = $this->get("jms_serializer");, (*8)

    $serializerGroup = array('view');

    $sc = SerializationContext::create();
    $sc->setGroups($serializerGroup);

    $jsonUser = $serializer->serialize($user,'json',$sc); //Generating the json target of object that we want to update
    $jsonUser = $jps->patch($jsonUser,$json); //json result with the changes applied of the json operations

    $dc = DeserializationContext::create();
    $dc->setAttribute('target',$user);

    //Restore the doctrine entity object with deserialization and targeting the object with DeserializationContext
    $serializer->deserialize($jsonUser,'Groupalia\BizApiBundle\Entity\User','json',$dc);

    $em = $this->getDoctrine()->getManager();
    $em->persist($user);
    $em->flush();

    $response = new Response();
    $response->setStatusCode(200);

    return $response;

}

```, (*9)

Thanks to

*https://github.com/webnium, (*10)

*https://github.com/javadegava, (*11)

*http://williamdurand.fr/2014/02/14/please-do-not-patch-like-an-idiot/, (*12)

*http://www.groupalia.com/, (*13)

The Versions

16/01 2015

dev-master

9999999-dev https://github.com/victuxbb/jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

json json pointer json operations patch operations

12/01 2015

v1.0.1

1.0.1.0 https://github.com/victuxbb/jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

json json pointer json operations patch operations

12/01 2015

dev-develop

dev-develop https://github.com/victuxbb/jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

json json pointer json operations patch operations

18/12 2014

v1.0.0

1.0.0.0 https://github.com/victuxbb/jsonpatch

Implementation of JSON Patch (http://tools.ietf.org/html/rfc6902)

  Sources   Download

MIT

The Requires

 

The Development Requires

json json pointer json operations patch operations