DDC-2910: JSON Pointer and JSON Patch syntax support #3669

doctrinebot opened this Issue Jan 12, 2014 · 3 comments

2 participants


Jira issue originally created by user dunglas:

I plan to add support for JSON Pointer (RFC 6901: http://tools.ietf.org/html/rfc6901) and JSON Patch (RFC 6902: http://tools.ietf.org/html/rfc6902) syntaxes to Doctrine.

JSON Pointer and JSON Patch are useful to create Hypermedia REST API (HATEOAS).
Some higher level standards such as JSON API (http://jsonapi.org/) also rely on JSON Pointer and JSON Patch. My final thought is to implement JSON API support (serialization and update) on top of the Doctrine ORM.

The use case for the JSON pointer syntax is to access entity properties through an object graph.


$jpa = new JsonPointerAccess();
$jpa->get($myEntityOrCollection, '/foo/0/bar'); # Get the value of $myEntityOrCollection->$foo[0]->bar
$jpa->set($myEntityOrCollection, '/foo/0/bar', 22); # Set the value of $myEntityOrCollection->$foo[0]->bar to 22

And for JSON Patch it's to modify a whole object graph.

$jpe = new JsonPatchExecuter();
$jpe->apply($myEntityOrCollection, '{ "op": "replace", "path": "/a/b/c", "value": 42 }'); # Set the value of $myEntityOrCollection->a->b->c to 42

In order to add some security, I also plan to create a new annotation to set access permissions on properties.

Ex :

use Doctrine\ORM\Mapping as ORM;

class MyEntity {
   * @ORM\Column(type="integer")
   * @ORM\Id
   * @ORM\Expose({"group_read"})
   public $id;

$jpa = new JsonPointerAccess();
$jpa->get($myEntity, '/id', ['group_read']); # OK
$jpa->set($myEntity, '/id', 22, ['group_read']); # Throw an exception

I'd like some feedback before starting the implementation:

  • Do you thing a such component should be in Doctrine or in a separate package?
  • What do you think of the purposed syntax?
  • Do you see other important features in this scope I've missed?

Thank you.


Comment created by @ocramius:

This idea is out of scope for ORM.

There's different projects you may look at:

These are obviously all trying to integrate with third party components, but the problem of REST APIs is out of the scope of persistence.
Please ping the people that are maintaining these projects before jumping forward and implementing from scratch.

And yes, the example API you've shown here is awesome - just out of scope for this project


Issue was closed with resolution "Won't Fix"


Comment created by dunglas:

Thanks for your reply.

I'm aware of these projects and in touch with people building HATEOAS (as a Symfony developper, other projects you mention are awesome but not fit my use case): willdurand/Hateoas#130

It seems that it's not easy to implement JSON API / Patch /Pointer in this kind of libraries but I'm keeping an eye on it. Maybe that a tiny library focusing on JSON stuffs support (instead of all hypermedia related things like HATEOAS) can be a good start (and maybe that some code can be shared between projects).

@Ocramius Ocramius was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment