News for hackers. Stuff that matters.
Re:Unlocking the Power of JSON Patch by ndr on Saturday October 19, 2024 @07:17AM (#41887172)
How does it handle arrays/repeated fields?

Eg: how do you update a field of the third element on an array when there are 5 elements in an array?

The same that in `jq` would be:

`jq ".people[2].age |= 50" example.json`

Re:Unlocking the Power of JSON Patch by bpicolo on Saturday October 19, 2024 @08:45AM (#41887471)
You overwrite the entire array. Replacement is a safe, idempotent operation.

If you're concerned about concurrency for array updates, you'll usually need a form of concurrency control whether the database supports partial updates or not.

Re:Unlocking the Power of JSON Patch by account42 on Monday October 21, 2024 @10:32AM (#41904589)
Unless your array is only a relatively small part of the file this defeats the purpose of patching. And yes, concurrency is also an issue in simple cases (e.g. append/prepend) that json patch handles fine on its own.