jeko2000 / zjson

A reference Common Lisp JSON [en|de]coding library
0 stars 0 forks source link

Add support for JSON pointers #2

Open jeko2000 opened 4 years ago

jeko2000 commented 4 years ago

A JSON pointer, as described under RFC-6901, defines a string syntax that identifies a specific value within a JSON Object.

For instance, given the following JSON object:

   {
      "foo": ["bar", "baz"],
      "": 0,
      "a/b": 1,
      "c%d": 2,
      "e^f": 3,
      "g|h": 4,
      "i\\j": 5,
      "k\"l": 6,
      " ": 7,
      "m~n": 8
   }

then the following pointers evaluate to the consequent values:

    ""           // the whole document
    "/foo"       ["bar", "baz"]
    "/foo/0"     "bar"
    "/"          0
    "/a~1b"      1
    "/c%d"       2
    "/e^f"       3
    "/g|h"       4
    "/i\\j"      5
    "/k\"l"      6
    "/ "         7
    "/m~0n"      8
jeko2000 commented 4 years ago

This could potentially be idealized via a new, setf-able jso-pointer-get method.

(zjson:jso-pointer-get "/foo")
;; => ("bar" "baz")

(setf (zjson:jso-pointer-get "/foo/0") "foo")
;; => "foo"

(zjson:jso-pointer-get "/foo")
;; => ("foo" "baz")