RSS Feed

Lisp Project of the Day


You can support this project by donating at:

Donate using PatreonDonate using Liberapay

Or see the list of project sponsors.


Tests 😀
CI 🥺

This library implements RFC 6901 - a format for accessing nested JSON data-structures. It some sense, JSON pointer is similar to JSON path, but more suitable for use as a part of the URL fragment.

cl-json-pointer's README provides many examples, but all of them are applied to the object which almost flat. Let's try to reproduce an example from the JSON path's site:

  "firstName": "John",
  "lastName" : "doe",
  "age"      : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  "phoneNumbers": [
      "type"  : "iPhone",
      "number": "0123-4567-8888"
      "type"  : "home",
      "number": "0123-4567-8910"

Now we'll translate this JSON path: $.phoneNumbers[0].type into JSON pointer /phoneNumbers/0/type:

POFTHEDAY> (defparameter *obj* 
              (alexandria:read-file-into-string "data.json")))

POFTHEDAY> (cl-json-pointer:get-by-json-pointer *obj* "/phoneNumbers/0/type"
                                                :flavor :jsown)
("type" . "iPhone")

It is also possible to add/set/delete elements using cl-json-pointer.

You will find more examples in the official docs.

Comparing to the JSON path, the pointer has clearer character escaping rules and is able to work with keys containing dots and slashes and other symbols. But it does not support slicing and some other features of the JSON path.

Brought to you by 40Ants under Creative Commons License