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

Closed
opened 2026-01-22 14:24:11 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 12, 2014).

Originally assigned to: @Ocramius on GitHub.

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.

Ex:

$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.

Originally created by @doctrinebot on GitHub (Jan 12, 2014). Originally assigned to: @Ocramius on GitHub. 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. Ex: ``` $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.
admin added the New Feature label 2026-01-22 14:24:11 +01:00
admin closed this issue 2026-01-22 14:24:11 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 12, 2014):

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

@doctrinebot commented on GitHub (Jan 12, 2014): Comment created by @ocramius: This idea is out of scope for ORM. There's different projects you may look at: - https://github.com/willdurand/Hateoas - https://github.com/leedavis81/drest - https://github.com/zf-fr/ZfrRest 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
Author
Owner

@doctrinebot commented on GitHub (Jan 12, 2014):

Issue was closed with resolution "Won't Fix"

@doctrinebot commented on GitHub (Jan 12, 2014): Issue was closed with resolution "Won't Fix"
Author
Owner

@doctrinebot commented on GitHub (Jan 12, 2014):

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): https://github.com/willdurand/Hateoas/issues/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).

@doctrinebot commented on GitHub (Jan 12, 2014): 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): https://github.com/willdurand/Hateoas/issues/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).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3623