C Collections

cjson · Section 3

cjson_remove

cjson_remove - remove and free the DOM node at a dot-separated path

C Collections (libccollections, -lccollections)

#include <ccollections/cjson.h>
 
ccol_retval cjson_remove(cjson root, const char *path);

Walks to the parent of the node that path addresses, removes that
child from it and frees the child's whole subtree.  The path has the
same dot-separated syntax as in cjson_get and cjson_set.
 
When the parent is a dictionary, the leaf component is the key to
remove.  When it is a list, the leaf component must be a '#N' token,
so "#2" removes index 2.
 
The path is split at its LAST unescaped dot, so "a.b.c" targets the
key "c" inside the node at "a.b".  A path with no dot has root as
its parent.
 
The escapes '\.' and '\\' give a literal dot and a literal
backslash in a key name, as they do in cjson_get and cjson_set.

ccol_retval, which is ccol_success on success.
ccol_invalid_args when root or path is NULL; for an empty path or an
empty path component (a leading dot, a trailing dot or two dots in a
row); for a path whose shape cannot apply to the tree, at any
position (a component that has to descend into or below a string, a
number, a bool or null, or a component on a list that is not '#N');
for a malformed "#N" index on a list, at any position; and for a
component above the leaf that is not valid UTF-8.  A syntax error
wins over an absent component earlier in the path.
ccol_key_not_found only when a well-formed name or index is absent,
above the leaf or at it.  An index with any number of digits is well
formed, so an index too large for any integer type also gives
ccol_key_not_found.
ccol_not_enough_memory when an internal allocation fails.

cjson_remove(doc, "users.#0.address");
cjson_remove(doc, "config.debug");
cjson_remove(doc, "items.#2");

cjson_get(3), cjson_set(3), cjson_dictionary_remove(3), cjson_list_remove(3)