←back to thread

JSON Patch

(zuplo.com)
299 points DataOverload | 1 comments | | HN request time: 0.356s | source
Show context
theendisney ◴[] No.41883153[source]
I imagine something like so:

   {
   "delete":["123-234","567-700"],

   "insert":[123,456],

   "substrs":[{"foo":"bar"},[]]
   }
Then delete the ranges from the string, convert the substrs to strings and insert them at the offset.
replies(1): >>41884836 #
Izkata ◴[] No.41884836[source]
I'm not sure I understand what you mean, but it almost sounds like something we already have a single verb for: "splice". It means "replace this range with these values":

  z = ['a', 'b', 'c', 'd', 'e', 'f']
  z.splice(2, 3, 'w', 'x', 'y', 'z')

  Array(7) [ "a", "b", "w", "x", "y", "z", "f" ]
Unfortunately it's not on strings in javascript, but the verb has basically that meaning even outside of programming and could work here too.

I don't see how the values in your example would work though.

replies(1): >>41885564 #
1. theendisney ◴[] No.41885564[source]
That seems to be it.

You compare the old string with the new one. What should be deleted is marked for deletion. Say char 10 to 30. Then the insert part points at spots where new stuff should be inserted.

Commas are left as an exercise for the backend.