←back to thread

JSON Patch

(zuplo.com)
299 points DataOverload | 9 comments | | HN request time: 1.724s | source | bottom
1. graypegg ◴[] No.41880930[source]
I'm probably missing a use case here, but with the JSON Pointer spec they use feeling so "URL-y", couldn't you skip the whole meta-json syntax? So rather than doing

    HTTP/1.1 PATCH /user
    Content-Type: application/json-patch+json

    [
      {
        "op": "replace",
        "path": "/username",
        "value": "bob"
      }
    ]
why not

    HTTP/1.1 PATCH /user/username
    Content-Type: application/json

    "bob"
I feel like you could pretty sensibly implement replace/delete/append with that.

Edit: "test" and "copy" from the json patch spec are unique! So there is those, as well as doing multiple edits all at once in a sort of "transaction".

replies(3): >>41880995 #>>41881640 #>>41883343 #
2. kukkamario ◴[] No.41880995[source]
And then you'd be limited to only one change at the time and lose the benefit of making lot of changes with one request.
replies(1): >>41881038 #
3. graypegg ◴[] No.41881038[source]
I do get that, just saw the "test" op, to either pass or fail the whole change as a sort of transaction. That is really neat.

But I just find that the 1 by 1 approach is easier to reason about if you're opening this up to the internet. I'd personally feel more comfortable with the security model of 1 URL + Session => 1 JSON key.

replies(3): >>41881983 #>>41882210 #>>41883362 #
4. DataOverload ◴[] No.41881640[source]
You might like JSON Merge Patch then - much simpler syntax that avoids the URL stuff
5. mattmanser ◴[] No.41881983{3}[source]
I'm actually using it at the moment in my work and I'm often doing 3-4 updates per patch.

You want them to all fail or not,

One-by-one is a bit of a weird suggestion tbh. You shouldn't be reasoning that way about code.

If you are going to get a 4xx response to one of the 4 property updates you want them all to fail at once.

Just like anything else we use like SQL.

6. vlowther ◴[] No.41882210{3}[source]
$WORK project heavily utilizes the test op to enable atomic updates to objects across multiple competing clients. It winds up working really well for that purpose.
replies(1): >>41890715 #
7. ks2048 ◴[] No.41883343[source]
IMHO, the "JSON patch" concept is useful in contexts that have nothing to HTTP, just like having a "diff" format for files.
8. kchr ◴[] No.41883362{3}[source]
Can you elaborate on how this affects the security model?
9. CrimsonRain ◴[] No.41890715{4}[source]
Who generates the test op? Client? Or the server?