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

Use JSONPatch format #6

Open
NV opened this issue Oct 30, 2014 · 1 comment
Open

Use JSONPatch format #6

NV opened this issue Oct 30, 2014 · 1 comment

Comments

@NV
Copy link
Owner

NV commented Oct 30, 2014

http://jsonpatch.com/

@fresheneesz
Copy link

JSONPatch has two oddities I can see:

  1. The JSON Pointer format uses weird escape codes, I assume because doing that saves a couple bytes here and there
  2. The remove item can't specify a count, so if you remove a big sequence from an array, you get a ton of little removal events (strange since this totally negates the bytes saved by JSON Pointer)

This is a format I would recommend instead:

  • type - Either "set", "add", or "rm"
  • path - An array representing the path from the root object. For example, ["a",2,"b] represents valueA.a[2].b. Will be an empty
    array if the change applies to the top-level object (ie valueA directly).
  • val - The value the indicated property was changed to. Only defined for the "set" type.
  • index - The index at which an item was added or removed from an array. Only defined for the "add" and "rm" types.
  • vals - An array of values added into the indicated property. Only defined for the "add" type.
  • num - The number of items removed from the indicated property. Only defined for the "remove" type.

Yes its not an RFC standard.. but its better. When looping through that kind of output, you can easily check to see if a path applies to whatever you're doing, because you can check every part of the path (maybe you only care about result.path.slice(0,2) for example). With JSONPatch you need to remember to apply some de-escape-code function to get the path in a usable format (unless you know for sure you don't currently and never will have keys with ~ or / in them).

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

2 participants