json-tree.h revision fcd3d6214ce1b8169b6481c78e02d9054901fed3
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen/* Direct access to this structure is not encouraged, use the inline
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen function accessors where possible, so that the implementation
3e0bae44b65f5c46989fcef3d1e07203f496327eTimo Sirainen details can remain fluid, or, even better, hidden. */
3e0bae44b65f5c46989fcef3d1e07203f496327eTimo Sirainen /* object key, or NULL if we're in a list */
3e0bae44b65f5c46989fcef3d1e07203f496327eTimo Sirainen const char *key;
e8490a52a1bc71bc53034e68f464435684ad810fTimo Sirainen /* for JSON_TYPE_OBJECT and JSON_TYPE_ARRAY */
7fd51f7b0b4d990ec3cfef4e60ee685bf9fb32deTimo Sirainen /* for other types */
7fd51f7b0b4d990ec3cfef4e60ee685bf9fb32deTimo Sirainen const char *str;
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainenstatic inline ATTR_PURE const struct json_tree_node *json_tree_get_child(const struct json_tree_node *node)
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainenstatic inline ATTR_PURE const char *json_tree_get_value_str(const struct json_tree_node *node)
32e1554df9abca74fef0af2ba2e4c37e90a06cd0Timo Sirainen/* You can build a list or an object, nothing else. */
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainenstruct json_tree *json_tree_init_type(enum json_type container);
32e1554df9abca74fef0af2ba2e4c37e90a06cd0Timo Sirainenstatic inline struct json_tree *json_tree_init(void)
b337d3b6871b878d6467d7d8ed600433af5da5a1Timo Sirainenstatic inline struct json_tree *json_tree_init_array(void)
16db188cfddce117500a161302f17ae691b4500eTimo Sirainenvoid json_tree_deinit(struct json_tree **tree);
16db188cfddce117500a161302f17ae691b4500eTimo Sirainen/* Append data to a tree. The type/value should normally come from json-parser.
296dca49e4fe6046e0328c67ef1cf4b8077dec9cTimo Sirainen Returns 0 on success, -1 if the input was invalid (which should never happen
296dca49e4fe6046e0328c67ef1cf4b8077dec9cTimo Sirainen if it's coming from json-parser). */
e8490a52a1bc71bc53034e68f464435684ad810fTimo Sirainenint json_tree_append(struct json_tree *tree, enum json_type type,
2b95b7a9f4f06e7640ef431d9e6efc2423cacf1aTimo Sirainen const char *value);
6145bd3b17b9135b77b0b42409a0cc3fa0d1b946Timo Sirainen/* Return the root node. */
296dca49e4fe6046e0328c67ef1cf4b8077dec9cTimo Sirainen/* Find a node with the specified key from an OBJECT node */
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainenjson_tree_find_key(const struct json_tree_node *node, const char *key);
e8490a52a1bc71bc53034e68f464435684ad810fTimo Sirainen/* Find an object node (from an array), which contains the specified key=value
e8490a52a1bc71bc53034e68f464435684ad810fTimo Sirainen in its values. */