Skip to content

Use JSONPatch format #6

Open
Open

Description

Activity

  1. fresheneesz commented on Jul 3, 2015

    @fresheneesz

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions