(text json pointer) - JSON Pointer

Library (text json pointer)

This library provides JSON Pointer procedures.

The specification of JSON Pointer is defined by the RFC 6901.

The following example shows simple usage of the library:

This is an input file named example.json.

{
  "id": 1234,
  "data": {
    "datum0": [0, 1, 2],
    "datum1": [3, 4]
  }
}
(import (rnrs) (rfc json-pointer) (text json))

(define id-pointer (json-pointer "/id"))

(let ((json (call-with-input-file "example.json" json-read)))
  (id-pointer json))
1234

(import (rnrs) (rfc json-pointer) (text json))

(define data-pointer (json-pointer "/data"))

#|
example.json
|#
(let ((json (call-with-input-file "example.json" json-read)))
  ;; Retrievs /data/datum0
  ((json-pointer "/datum0" data-pointer) json))
'(0 1 2)

Function json-pointer pointer: optional parent

Returns a procedure taks one argument which must be a list or vector representing JSON object. The given poinster must be a string or textual input port which start with /.

The optional argument parent is passed, then it must be a procedure returned by the json-pointer and is called before the current pointer is processed.