Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batches from a base path to decrease the amount of text required. #9

Open
disordinary opened this issue Oct 30, 2014 · 3 comments
Open

Comments

@disordinary
Copy link

Having the paths in ever operation seems needlessly verbose for batches of updates, so I propose the introduction of batches.

If I had an object:

    {
        id,
        name,
        password,
        email,
        phone
    }

And I wanted to replace the email and phone items I would need to go:

    {"op": "replace", "path": "/user/0/email", "value": "[email protected]"}

    {"op": "replace", "path": "/user/0/phone", "value": "+64 4 555 5555"}

If I have big objects with lots of changes then that is going to be allot of information to transport, something like:

    {"op": "replace", "path": "/user/0/", "patch": 
            { "email": "[email protected]", "phone": "+64 4 555 5555"}
    }
@mkantor
Copy link

mkantor commented Oct 30, 2014

How about a general-purpose scope operation whose value is an arbitrary JSON patch array?

[
  { "op": "scope", "path": "/user/0", "value": [
    { "op": "replace", "path": "/email", "value": "[email protected]" },
    { "op": "replace", "path": "/phone", "value": "+64 4 555 5555" },
    { "op": "remove", "path": "/password" }
  ] },
  { "op": "add", "path": "/hello", "value": ["world"] }
]

@disordinary
Copy link
Author

Yes that's a good idea, and you could have scopes within scopes. In this case the paths within the scopes should be relative. The leading / would indicate that they would go back to the root of the object, so they should start with a ./ or nothing, i.e. ./email, ./phone or email, phone, you could theoretically also have ../1/email to modify something outside of the path, in that case modify /user/1/ instead of /user/0/ but that is getting silly.

[
  { "op": "scope", "path": "/user/0", "value": [
    { "op": "replace", "path": "email", "value": "[email protected]" },
    { "op": "replace", "path": "phone/office", "value": "+64 4 555 5555" },
    { "op": "remove", "path": "password" }
  ] },
  { "op": "add", "path": "/hello", "value": ["world"] }
]

It's still too much duplicated text and information for my liking. I'm thinking if you are storing millions of patches or sending thousands of patches down the wire, but if you are clever with nested scopes it is much more efficient than having every operation separate.

@mitar
Copy link

mitar commented Oct 12, 2019

I would be against this proposal because I think this is premature optimization. These days it is easy to use some compression algorithm on top of the transport you are using for your JSON patches, which would make deduplicate such repetitions. I would not complicate the PATCH format itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants