![]() |
Oyranos
0.9.7
Oyranos is a full featured Color Management System
|
Easy to use JSON API. More...
Functions | |
oyjl_val | oyjl_tree_parse (const char *input, char *error_buffer, size_t error_buffer_size) |
read a json text string into a C data structure More... | |
char * | oyjl_value_text (oyjl_val v, void *(*alloc)(size_t size)) |
get the value as text string with user allocator More... | |
void | oyjl_tree_to_paths (oyjl_val root, int levels, const char *xpath, int flags, char ***paths) |
find matching paths More... | |
void | oyjl_tree_to_json (oyjl_val v, int *level, char **json) |
convert a C tree into a JSON string More... | |
int | oyjl_value_count (oyjl_val v) |
return the number of members if any at the node level More... | |
oyjl_val | oyjl_value_pos_get (oyjl_val v, int pos) |
obtain a child node at the nth position from a object or array node More... | |
int | oyjl_path_match (const char *path, const char *xpath) |
search for xpath pattern matching in a full path More... | |
oyjl_val | oyjl_tree_new (const char *xpath) |
create a node by a path expression More... | |
oyjl_val | oyjl_tree_get_value (oyjl_val v, int flags, const char *xpath) |
obtain a node by a path expression More... | |
oyjl_val | oyjl_tree_get_valuef (oyjl_val v, int flags, const char *format,...) |
get a child node by a path expression More... | |
int | oyjl_value_set_string (oyjl_val v, const char *string) |
set the node value to a string More... | |
void | oyjl_value_clear (oyjl_val v) |
release all childs recursively More... | |
void | oyjl_tree_clear_value (oyjl_val root, const char *xpath) |
release a specific node and all its childs More... | |
void | oyjl_tree_free (oyjl_val v) |
release a node and all its childs recursively More... | |
Easy to use JSON API.
The API is designed to be easily useable without much boilerplate. It includes a xpath alike syntax to obtain or create nodes inside a tree. A path string is constructed of terms and the slash delimiter '/'. Understood terms are object names or the squared brackets index operator [].
Path Example:
"foo/[3]/bar" will return the "bar" node with the "found" string.
{ "foo": [ { "ignore": 0 }, { "ignore_too": 0 }, { "ignore_it": 0 }, { "bar": "found" } ] }
Some API's accept extended paths expressions. Those can contain empty terms, like "//", which matches all keys in the above example.
Programming Tutorial
The following code examples come from tutorial_json_options.c .
int oyjl_path_match | ( | const char * | path, |
const char * | xpath | ||
) |
search for xpath pattern matching in a full path
void oyjl_tree_clear_value | ( | oyjl_val | root, |
const char * | xpath | ||
) |
release a specific node and all its childs
In case parents have no children, release them or clear root.
References oyjl_tree_free(), oyjl_tree_get_value(), and oyjl_value_clear().
void oyjl_tree_free | ( | oyjl_val | v | ) |
release a node and all its childs recursively
References oyjl_value_clear().
Referenced by oyjl_tree_clear_value().
oyjl_val oyjl_tree_get_value | ( | oyjl_val | v, |
int | flags, | ||
const char * | xpath | ||
) |
obtain a node by a path expression
Referenced by oyjl_tree_clear_value(), and oyjl_tree_get_valuef().
oyjl_val oyjl_tree_get_valuef | ( | oyjl_val | v, |
int | flags, | ||
const char * | format, | ||
... | |||
) |
get a child node by a path expression
Function oyjl_tree_get_valuef Creating a new node inside a existing tree needs just a root node - v. The flags should contain OYJL_CREATE_NEW.
Example: "foo/[]/bar" will append a node to the foo array and create the bar node, which is empty.
[in] | v | the oyjl node |
[in] | flags | OYJL_CREATE_NEW - returns nodes even if they did not yet exist |
[in] | format | the format for the slashed path string |
[in] | ... | the variable argument list; optional |
References oyjl_tree_get_value().
oyjl_val oyjl_tree_new | ( | const char * | xpath | ) |
create a node by a path expression
A NULL argument allocates just a node of type oyjl_t_null.
oyjl_val oyjl_tree_parse | ( | const char * | input, |
char * | error_buffer, | ||
size_t | error_buffer_size | ||
) |
read a json text string into a C data structure
void oyjl_tree_to_json | ( | oyjl_val | v, |
int * | level, | ||
char ** | json | ||
) |
convert a C tree into a JSON string
References oyjl_tree_to_json().
Referenced by oyjl_tree_to_json().
void oyjl_tree_to_paths | ( | oyjl_val | root, |
int | levels, | ||
const char * | xpath, | ||
int | flags, | ||
char *** | paths | ||
) |
find matching paths
root | node |
levels | desired level depth |
xpath | extented path expression; It accepts even empty terms. |
flags | support filters:
|
xpaths | the resulting string list |
void oyjl_value_clear | ( | oyjl_val | v | ) |
release all childs recursively
Referenced by oyjl_tree_clear_value(), oyjl_tree_free(), and oyjl_value_set_string().
int oyjl_value_count | ( | oyjl_val | v | ) |
return the number of members if any at the node level
This function is useful to traverse through objects and arrays of a unknown JSON tree.
oyjl_val oyjl_value_pos_get | ( | oyjl_val | v, |
int | pos | ||
) |
obtain a child node at the nth position from a object or array node
int oyjl_value_set_string | ( | oyjl_val | v, |
const char * | string | ||
) |
char* oyjl_value_text | ( | oyjl_val | v, |
void *(*)(size_t size) | alloc | ||
) |
get the value as text string with user allocator