(apply-value json paths value)
(apply-value json paths value opts-map)
Given json
, a JSONPath string paths
, and the JSON data
value
, apply value
to the location given by paths
If
the location exists, update the pre-existing value. Otherwise,
create the necessary data structures needed to contain value
.
The following caveats apply:
json
is overwritten in
its entirety.The following opts-map
fields are supported:
:first? Apply only the first "|"-separated path. Default
false.
:strict? If provided, always overrides to true.
Given `json`, a JSONPath string `paths`, and the JSON data `value`, apply `value` to the location given by `paths` If the location exists, update the pre-existing value. Otherwise, create the necessary data structures needed to contain `value`. The following caveats apply: - If only the root "$" is provided, `json` is overwritten in its entirety. - If an array index skips over any vector entries, those skipped entries will be assigned nil. - If a path contains a wildcard and the location up to that point does not exist, create a new vector. - If a path contains a wildcard and the location is a collection, append it to the coll. In the case of maps, the key is its current size, e.g. {"2" : "foo"}. - Recursive descent, array slicing, and negative array indices are disallowed (as per strict mode). The following `opts-map` fields are supported: :first? Apply only the first "|"-separated path. Default false. :strict? If provided, always overrides to true.
(apply-value* json paths value)
Like apply-value
except that the paths
argument is a vector of
already-parsed JSONPaths.
Does not support an opts-map
argument.
Like `apply-value` except that the `paths` argument is a vector of already-parsed JSONPaths. Does not support an `opts-map` argument.
(excise json paths)
(excise json paths opts-map)
Given json
and a JSONPath string paths
, return the JSON value with
the elements at the location removed.
The following opts-map
fields are supported:
:first? Only apply the first "|"-separated path.
:strict? Disallow recursive descent, array slicing, and
negative array indices.
:prune-empty? Removes empty maps and vectors, as well as
key-value pairs where values are empty, after the
elements are excised. Default false.
Given `json` and a JSONPath string `paths`, return the JSON value with the elements at the location removed. The following `opts-map` fields are supported: :first? Only apply the first "|"-separated path. :strict? Disallow recursive descent, array slicing, and negative array indices. :prune-empty? Removes empty maps and vectors, as well as key-value pairs where values are empty, after the elements are excised. Default false.
(excise* json paths)
(excise* json paths opts-map)
Like excise
except that the paths
argument is a vector of
already-parsed JSONPaths.
The following opts-map
fields are supported:
:prune-empty? Removes empty maps and vectors, as well as
key-value pairs where values are empty, after the
elements are excised. Default false.
Like `excise` except that the `paths` argument is a vector of already-parsed JSONPaths. The following `opts-map` fields are supported: :prune-empty? Removes empty maps and vectors, as well as key-value pairs where values are empty, after the elements are excised. Default false.
(get-path-value-map json paths)
(get-path-value-map json paths opts-map)
Given json
nd a JSONPath string paths
, return a map associating
JSON paths to JSON values. Does not return duplicates.
The following opts-map
fields are supported:
:first? Only apply the first "|"-separated path.
:strict? Disallow recursive descent, array slicing,
and negative array indices.
:return-missing? Return path-value pairs where the path cannot
match any location in the json
The result val
is returned as nil. Default false.
Given `json` nd a JSONPath string `paths`, return a map associating JSON paths to JSON values. Does not return duplicates. The following `opts-map` fields are supported: :first? Only apply the first "|"-separated path. :strict? Disallow recursive descent, array slicing, and negative array indices. :return-missing? Return path-value pairs where the path cannot match any location in the `json` The result val is returned as nil. Default false.
(get-path-value-map* json paths)
(get-path-value-map* json paths opts-map)
Like get-path-value-map
except that the paths
argument is a
vector of already-parsed JSONPaths.
The following opts-map
fields are supported:
:return-missing? Return path-value pairs where the path cannot
match any location in the json
The result val
is returned as nil. Default false.
Like `get-path-value-map` except that the `paths` argument is a vector of already-parsed JSONPaths. The following `opts-map` fields are supported: :return-missing? Return path-value pairs where the path cannot match any location in the `json` The result val is returned as nil. Default false.
(get-paths json paths)
(get-paths json paths opts-map)
Given json
and a JSONPath string paths
, return a vector of
definite key paths. Each key path is a vector of strings (keys)
or integers (array indices); non-deterministic path entries like
recursive descent and wildcards are removed. If the string
contains multiple JSONPaths, we return the key paths for all
strings.
The following opts-map
fields are supported:
:first? Only apply the first "|"-separated path.
:strict? Disallow recursive descent, array slicing,
and negative array indices.
:return-missing? Return partial paths for paths that cannot
match any location in json
. Default false.
Given `json` and a JSONPath string `paths`, return a vector of definite key paths. Each key path is a vector of strings (keys) or integers (array indices); non-deterministic path entries like recursive descent and wildcards are removed. If the string contains multiple JSONPaths, we return the key paths for all strings. The following `opts-map` fields are supported: :first? Only apply the first "|"-separated path. :strict? Disallow recursive descent, array slicing, and negative array indices. :return-missing? Return partial paths for paths that cannot match any location in `json`. Default false.
(get-paths* json paths)
(get-paths* json paths opts-map)
Like get-paths
except that the paths
argument is a vector
of already-parsed JSONPaths.
The following opts-map
fields are supported:
:return-missing? Return partial paths for paths that cannot
match any location in json
. Default false.
Like `get-paths` except that the `paths` argument is a vector of already-parsed JSONPaths. The following `opts-map` fields are supported: :return-missing? Return partial paths for paths that cannot match any location in `json`. Default false.
(get-values json paths)
(get-values json paths opts-map)
Given json
and a JSONPath string paths
, return a vector of
JSON values. If the string contains multiple JSONPaths, we return
the union of all these values.
The following opts-map
fields are supported:
:first? Only apply the first "|"-separated path.
:strict? Disallow recursive descent, array slicing,
and negative array indices.
:return-missing? Return values that cannot be found in json
as nil. Default false.
:return-duplicates? Return duplicate values in the result.
Default true.
Given `json` and a JSONPath string `paths`, return a vector of JSON values. If the string contains multiple JSONPaths, we return the union of all these values. The following `opts-map` fields are supported: :first? Only apply the first "|"-separated path. :strict? Disallow recursive descent, array slicing, and negative array indices. :return-missing? Return values that cannot be found in `json` as nil. Default false. :return-duplicates? Return duplicate values in the result. Default true.
(get-values* json paths)
(get-values* json paths opts-map)
Like get-values
except that the paths
argument is a vector
of already-parsed JSONPaths.
The following opts-map
fields are supported:
:return-missing? Return values that cannot be found in json
data as nil. Default false.
:return-duplicates? Return duplicate values in the result.
Default true.
Like `get-values` except that the `paths` argument is a vector of already-parsed JSONPaths. The following `opts-map` fields are supported: :return-missing? Return values that cannot be found in `json` data as nil. Default false. :return-duplicates? Return duplicate values in the result. Default true.
(parse-paths paths)
(parse-paths paths opts-map)
Given a JSONPath string paths
, parse the string. Each parsed
path is a vector of the following elements:
'.. recursive descent operator
'* wildcard operator
[...] a vector of strings (keys), integers (array indices), or
maps (array slicing operations).
The following opts-map
fields are supported:
:first? Return a singleton vector containing the first path
when multiple paths are joined using "|". Default
false.
:strict? If true, disallows recursive descent, array slicing,
and negative indices. Conformant to the xAPI Profile
spec. Default false.
Given a JSONPath string `paths`, parse the string. Each parsed path is a vector of the following elements: '.. recursive descent operator '* wildcard operator [...] a vector of strings (keys), integers (array indices), or maps (array slicing operations). The following `opts-map` fields are supported: :first? Return a singleton vector containing the first path when multiple paths are joined using "|". Default false. :strict? If true, disallows recursive descent, array slicing, and negative indices. Conformant to the xAPI Profile spec. Default false.
(select-keys-at json paths)
(select-keys-at json paths opts-map)
Given json
and a JSONPath string paths
, return a map or
vector of maps representing the key path into json
. If the string
contains multiple JSONPaths, we return the maps for all strings.
If no value exists at the selection, return a truncated map with
"{}" as the innermost possible value.
The following opts-map
fields are supported:
:first? Returns only the map corresponding to the first
"|"-separated path. Default false.
:strict? Disallow recursive descent, array slicing, and negative
array indices. Default false.
Given `json` and a JSONPath string `paths`, return a map or vector of maps representing the key path into `json`. If the string contains multiple JSONPaths, we return the maps for all strings. If no value exists at the selection, return a truncated map with "{}" as the innermost possible value. The following `opts-map` fields are supported: :first? Returns only the map corresponding to the first "|"-separated path. Default false. :strict? Disallow recursive descent, array slicing, and negative array indices. Default false.
(select-keys-at* json paths)
Like select-keys-at
except that the paths
argument is a vector
of already-parsed JSONPaths.
Does not support an opts-map
argument.
Like `select-keys-at` except that the `paths` argument is a vector of already-parsed JSONPaths. Does not support an `opts-map` argument.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close