json/patch
src/json/patch.tur
defn
json-get-in
(json-get-in [doc : int path : cstr] :)
look up a value at a dot-separated path.
Parameters
| doc | :int doc handle from json-parse | |
| path | dot-separated key path, e.g. "user.address.city" |
Returns
:cstr -- the matched value serialized as JSON, or "" if not found
Example
(json-get-in doc "user.name") ; => "\"Alice\""
Since: P4
defn
json-set-in
(json-set-in [doc : int path : cstr value : cstr] :)
return a new doc with the value at a dot-separated path replaced.
Parameters
| doc | :int doc handle from json-parse | |
| path | dot-separated key path, e.g. "user.name" | |
| value | JSON string for the new value, e.g. "\"Bob\"" |
Returns
result<:int> -- ok(new-doc-handle) on success, err(:cstr message) on failure. The original doc handle is unchanged. The caller must json-free the new handle.
Example
(let [r (json-set-in doc "x" "42")]
(when (ok? r) (println (json-emit (ok-val r)))))
Since: P4
defn
json-merge
(json-merge [base : int overlay : int] :)
shallow-merge two JSON objects, returning a new doc.
Parameters
| base | :int doc handle for the base object | |
| overlay | :int doc handle whose keys overwrite base keys |
Returns
result<:int> -- ok(new-doc-handle) with merged object, or err(:cstr). The original handles are unchanged. Caller must json-free the new handle.
Example
(let [r (json-merge base overlay)]
(when (ok? r) (println (json-emit (ok-val r)))))
Since: P4
Internal definitions
__ok__err