{"size": 1436, "ext": "scrbl", "max_stars_repo_path": "doc/utils/text/json/pointer.scrbl", "max_stars_repo_name": "christoff-buerger/sagittarius-scheme", "max_stars_repo_stars_event_min_datetime": "2015-11-07T07:13:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T03:35:14.000Z", "max_issues_repo_path": "doc/utils/text/json/pointer.scrbl", "max_issues_repo_name": "christoff-buerger/sagittarius-scheme", "max_issues_repo_issues_event_min_datetime": "2016-04-28T21:59:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-01T08:42:21.000Z", "max_forks_repo_path": "doc/utils/text/json/pointer.scrbl", "max_forks_repo_name": "christoff-buerger/sagittarius-scheme", "max_forks_repo_forks_event_min_datetime": "2016-12-28T12:41:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-26T20:52:02.000Z"}
{"max_stars_count": 39, "max_issues_count": 3, "max_forks_count": 4, "avg_line_length": 25.6428571429, "max_line_length": 74, "alphanum_fraction": 0.6949860724}
@; -*- coding: utf-8 -*-
@subsection[:tag "text.json.pointer"]{(text json pointer) - JSON Pointer}

@define[Library]{@name{(text json pointer)}}
@desc{This library provides JSON Pointer procedures.

The specification of JSON Pointer is defined by the
@hyperlink[:href "https://tools.ietf.org/html/rfc6901"]{RFC 6901}.
}

The following example shows simple usage of the library:

This is an input file named @code{example.json}.
@codeblock{
{
  "id": 1234,
  "data": {
    "datum0": [0, 1, 2],
    "datum1": [3, 4]
  }
}
}

@codeblock[=> 1234]{
(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))
}

@codeblock[=> '(0 1 2)]{
(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))
}


@define[Function]{@name{json-pointer} @args{pointer: optional parent}}
@desc{Returns a procedure taks one argument which must be a list or vector
representing JSON object. The given @var{poinster} must be a string or
textual input port which start with @code{/}.

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