Liking cljdoc? Tell your friends :D

clj-lazy-json.core


build-automatonclj

(build-automaton opts paths-and-callbacks)

Used internally by process-json and define-json-processor. See the docstring on the latter for a description of the supported options and the path language. See the docstring on consume-json for a description of the basic behaviour implemented.

Used internally by process-json and define-json-processor.
See the docstring on the latter for a description of the supported
options and the path language. See the docstring on consume-json for
a description of the basic behaviour implemented.
sourceraw docstring

consume-jsonclj

(consume-json automaton events path)

Used internally by process-json and define-json-processor.

Used internally by process-json and define-json-processor.
sourceraw docstring

define-json-processorcljmacro

(define-json-processor name docstring? opts? & paths-and-callbacks)

Defines a function of the given name and, optionally, with the given docstring, which takes a single argument, a seq of parse events describing a JSON datum (as output by the parse and parse-string functions), and processes it lazily in accordance with the given specification.

Options are currently ignored.

Paths are specified using the following language: :$ matches the root datum only; :* matches any datum in the current position in the path; :** matches any subpath; a literal string matches an object entry at that key; a literal number matches an array entry at that index.

Callbacks receive two arguments: the complete path to the current node (starting at :$) and the clojurized representation of the node (as would be returned by clj-json or clojure.data.json).

Example:

(define-json-processor example-processor "A simple JSON processor." [:$ "foo" 0] #(do (apply prn "This is particularly interesting:" %&)) [:**] prn)

(example-processor (-> "{"foo": [1], "bar": [2]}" parse-string) ;; returns nil; printed output follows: [:$] {"foo" [1], "bar" [2]} [:$ "foo"] [1] "This is particularly interesting:" [:$ "foo" 0] 1 [:$ "foo" 0] 1 [:$ "bar"] [2] [:$ "bar" 0] 2

Defines a function of the given name and, optionally, with the
given docstring, which takes a single argument, a seq of parse
events describing a JSON datum (as output by the parse and
parse-string functions), and processes it lazily in accordance with
the given specification.

Options are currently ignored.

Paths are specified using the following language:
  :$ matches the root datum only;
  :* matches any datum in the current position in the path;
  :** matches any subpath;
  a literal string matches an object entry at that key;
  a literal number matches an array entry at that index.

Callbacks receive two arguments: the complete path to the current
node (starting at :$) and the clojurized representation of the
node (as would be returned by clj-json or clojure.data.json).

Example:

  (define-json-processor example-processor
    "A simple JSON processor."
    [:$ "foo" 0] #(do (apply prn "This is particularly interesting:" %&))
    [:**] prn)

  (example-processor (-> "{\"foo\": [1], \"bar\": [2]}"
                         parse-string)
  ;; returns nil; printed output follows:
  [:$] {"foo" [1], "bar" [2]}
  [:$ "foo"] [1]
  "This is particularly interesting:" [:$ "foo" 0] 1
  [:$ "foo" 0] 1
  [:$ "bar"] [2]
  [:$ "bar" 0] 2
sourceraw docstring

parseclj

(parse source)
(parse source factory)

Returns a seq of parse events for the given source.

Returns a seq of parse events for the given source.
sourceraw docstring

parse-stringclj

(parse-string s)

Parses the JSON document contained in the string s into a seq of parse events.

Parses the JSON document contained in the string s into a seq of parse events.
sourceraw docstring

process-jsonclj

(process-json parsed-json opts & paths-and-callbacks)

Constructs a one-off JSON processor and uses it to process parsed-json. See docstring on define-json-processor for processor definition syntax and supported options.

Constructs a one-off JSON processor and uses it to process parsed-json.
See docstring on define-json-processor for processor definition
syntax and supported options.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close