Liking cljdoc? Tell your friends :D

rewrite-json.zip

Zipper-based navigation and editing API for JSON/JSONC node trees.

Navigation functions (right, left, down, up) skip whitespace and comment nodes by default, while preserving them in the tree.

Usage: (require '[rewrite-json.zip :as z]) (require '[rewrite-json.parser :as parser])

(-> (z/of-string "{"name": "old"}") (z/find-key "name") z/right (z/replace (node/string-node "new")) z/root-string) ;; => "{"name": "new"}"

Zipper-based navigation and editing API for JSON/JSONC node trees.

Navigation functions (right, left, down, up) skip whitespace and
comment nodes by default, while preserving them in the tree.

Usage:
  (require '[rewrite-json.zip :as z])
  (require '[rewrite-json.parser :as parser])

  (-> (z/of-string "{\"name\": \"old\"}")
      (z/find-key "name")
      z/right
      (z/replace (node/string-node "new"))
      z/root-string)
  ;; => "{\"name\": \"new\"}"
raw docstring

append-elementclj

(append-element loc value-node)
source

append-entryclj

(append-entry loc key-name value-node)

Append a new key-value entry to an object. loc should be positioned at an object node. Tries to match the existing formatting style.

Append a new key-value entry to an object.
`loc` should be positioned at an object node.
Tries to match the existing formatting style.
sourceraw docstring

downclj

(down loc)
source

editclj

(edit loc f & args)
source

end?clj

(end? loc)
source

entry-valueclj

(entry-value entry-loc)

Given a zipper positioned at an entry node, return a zipper positioned at the entry's value node (the first value-node after the colon).

Given a zipper positioned at an entry node, return a zipper positioned
at the entry's value node (the first value-node after the colon).
sourceraw docstring

find-keyclj

(find-key loc key-name)

From the current location (which should be an object or positioned inside one), find the entry whose key matches key-name (string). Returns the zipper positioned at the entry node, or nil.

Note: clojure.zip/down on an empty children seq destructures to a nil node; we guard against that explicitly in the loop.

From the current location (which should be an object or positioned
inside one), find the entry whose key matches `key-name` (string).
Returns the zipper positioned at the entry node, or nil.

Note: clojure.zip/down on an empty children seq destructures to a nil
node; we guard against that explicitly in the loop.
sourceraw docstring

find-valueclj

(find-value loc v)
source

get-keyclj

(get-key loc key-name)
source

leftclj

(left loc)
source

leftmostclj

(leftmost loc)
source

nextclj

(next loc)
source

nodeclj

(node loc)
source

of-nodeclj

(of-node root)
source

of-stringclj

(of-string s)
source

pretty-value-nodeclj

(pretty-value-node value-node container-loc)

Convert value-node (already a node, typically from node/value->node) to a multi-line formatted node, using container-loc (a zipper loc positioned at the object/array that will contain the value) to infer the indentation level.

Uses infer-indent-with-context so that even freshly created empty containers inherit multi-line style from their ancestors.

When the container uses single-line formatting, or when value-node is a scalar, it is returned unchanged.

Convert `value-node` (already a node, typically from `node/value->node`)
to a multi-line formatted node, using `container-loc` (a zipper loc
positioned at the object/array that will contain the value) to infer
the indentation level.

Uses `infer-indent-with-context` so that even freshly created empty
containers inherit multi-line style from their ancestors.

When the container uses single-line formatting, or when `value-node` is
a scalar, it is returned unchanged.
sourceraw docstring

removeclj

(remove loc)

Remove the node at the current location from its parent container. Handles comma cleanup for objects and arrays.

Remove the node at the current location from its parent container.
Handles comma cleanup for objects and arrays.
sourceraw docstring

replaceclj

(replace loc new-node)
source

(right loc)
source

rightmostclj

(rightmost loc)
source

rootclj

(root loc)
source

root-stringclj

(root-string loc)
source

upclj

(up loc)
source

valueclj

(value loc)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close