|
JST: JSON tools
1.0.0
JSON tools dynamic library for reading, manipulating and writing JSON tree
|
#include "stdbool.h"#include "stdint.h"#include "stdio.h"

Go to the source code of this file.
Data Structures | |
| struct | JST_Array |
| A JSON array. More... | |
| struct | JST_Object |
| A JSON object, a sorted set of named-value pairs. More... | |
| union | JST_Value |
| A JSON Value may be an object, an array, a boolean, a number or a string. More... | |
| struct | JST_Element_ |
| An element is a typed value. More... | |
| struct | JST_ArrayItem_ |
| An array item has a parent and a typed value. More... | |
| struct | JST_Pair_ |
| A object attribute item has a parent and is a named-typed-value pair. More... | |
| struct | JST_SyntaxError |
| Information returned by JST_load() in case of error. More... | |
Typedefs | |
| typedef struct JST_Element_ | JST_Element |
| An element is a typed value. More... | |
| typedef struct JST_ArrayItem_ | JST_ArrayItem |
| An array item has a parent and a typed value. More... | |
| typedef struct JST_Pair_ | JST_Pair |
| A object attribute item has a parent and is a named-typed-value pair. More... | |
| typedef bool(* | JST_Visitor) (const char *name, unsigned index, bool pre, const JST_Element *element, void *user_context) |
| Visitor in depth first with 'pre' set to true then backtrack with 'pre' set to false. More... | |
Enumerations | |
| enum | JST_ValueType { JST_OBJECT, JST_ARRAY, JST_BOOLEAN, JST_INTEGER, JST_DOUBLE, JST_STRING, JST_NULL } |
| The JSON Value types. More... | |
| enum | JST_Error { JST_ERR_NONE, JST_ERR_NULL_ARGUMENT, JST_ERR_NULL_TYPE, JST_ERR_ERRNO, JST_ERR_STRING_NOT_ENDED, JST_ERR_STRING_BAD_ESCAPE_SEQUENCE, JST_ERR_STRING_CONTROL_CHAR_MUST_BE_ESCAPED, JST_ERR_SEPARATOR_EXPECTED_AFTER_TRUE, JST_ERR_SEPARATOR_EXPECTED_AFTER_FALSE, JST_ERR_SEPARATOR_EXPECTED_AFTER_NULL, JST_ERR_TRUE_EXPECTED, JST_ERR_FALSE_EXPECTED, JST_ERR_NULL_EXPECTED, JST_ERR_NUMBER_EXPECTED, JST_ERR_COLON_EXPECTED, JST_ERR_UNEXPECTED_TOKEN, JST_ERR_PATH_SYNTAX, JST_ERR_NOT_FOUND, JST_ERR_ARRAY_INDEX_OUT_OF_RANGE, JST_ERR_INTERRUPTED } |
| When things goes wrong, an error information is given. More... | |
Functions | |
| JST_Error | JST_load_from_file (const char *filepath, JST_Element *root, JST_SyntaxError *error) |
| Reads the input file, allocates the node of the corresponding tree, than frees the input buffer. More... | |
| JST_Error | JST_load_from_stream (FILE *stream, JST_Element *root, JST_SyntaxError *error) |
| Reads the input stream, allocates the node of the corresponding tree, than frees the input buffer. More... | |
| JST_Error | JST_save_to_stream (FILE *stream, const JST_Element *root, unsigned indent) |
| Save the JSON tree to a stream, pretty-printed. More... | |
| JST_Error | JST_save_to_file (const char *filepath, const JST_Element *root, unsigned indent) |
| Save the JSON tree to a file, pretty-printed. More... | |
| JST_Error | JST_save_to_stream_compact (FILE *stream, const JST_Element *root) |
| Save the JSON tree to a stream, as a single line of text, without whitespaces. More... | |
| JST_Error | JST_save_to_file_compact (const char *filepath, const JST_Element *root) |
| Save the JSON tree to a file, as a single line of text, without whitespaces. More... | |
| JST_Error | JST_serialize (JST_Element *root, char **dest, unsigned indent) |
| Serialize the JSON tree to a string, pretty-printed. More... | |
| JST_Error | JST_serialize_compact (JST_Element *root, char **dest) |
| Serialize the JSON tree to a string as a single line of text, without whitespaces. More... | |
| JST_Error | JST_get (const char *jsonpath, JST_Element *root, JST_Element **dest) |
| Search an element by its path. More... | |
| JST_Error | JST_add_property (JST_Object *object, unsigned index, const char *name, const JST_Element *value) |
| Add a named-value pair to an object. More... | |
| JST_Error | JST_remove_property (JST_Object *object, const char *name) |
| JST_Error | JST_add_item (JST_Array *array, const JST_Element *value) |
| JST_Error | JST_remove_item (JST_Array *array, unsigned index) |
| JST_Error | JST_replace_item (JST_Array *array, unsigned index, const JST_Element *value) |
| JST_Error | JST_walk (const JST_Element *root, JST_Visitor visitor, void *user_context) |
| JST_Error | JST_delete_pair (JST_Pair *element) |
| JST_Error | JST_delete_object (JST_Object *object) |
| JST_Error | JST_delete_array_item (JST_ArrayItem *array) |
| JST_Error | JST_delete_array (JST_Array *array) |
| JST_Error | JST_delete_element (JST_Element *element) |
Variables | |
| const JST_Array | JST_Array_Zero |
| Constant defined to initialize safely a variable of type JST_Array. More... | |
| const JST_Object | JST_Object_Zero |
| Constant defined to initialize safely a variable of type JST_Object. More... | |
| const JST_Value | JST_Value_Zero |
| Constant defined to initialize safely a variable of type JST_Value. More... | |
| const JST_Element | JST_Element_Zero |
| Constant defined to initialize safely a variable of type JST_Element. More... | |
| const JST_ArrayItem | JST_ArrayItem_Zero |
| const JST_Pair | JST_Pair_Zero |
| Constant defined to initialize safely a variable of type JST_Pair. More... | |
| const JST_SyntaxError | JST_SyntaxError_Zero |
| Constant defined to initialize safely a variable of type JST_SyntaxError. More... | |
| typedef struct JST_ArrayItem_ JST_ArrayItem |
An array item has a parent and a typed value.
| typedef struct JST_Element_ JST_Element |
An element is a typed value.
A object attribute item has a parent and is a named-typed-value pair.
| typedef bool(* JST_Visitor) (const char *name, unsigned index, bool pre, const JST_Element *element, void *user_context) |
| enum JST_Error |
When things goes wrong, an error information is given.
| Enumerator | |
|---|---|
| JST_ERR_NONE | All correct |
| JST_ERR_NULL_ARGUMENT | Function misused. |
| JST_ERR_NULL_TYPE | A type field has been set to JST_NONE. |
| JST_ERR_ERRNO | strerror() or perror() can be used to show the operating system layer error |
| JST_ERR_STRING_NOT_ENDED | ending quote has not been found |
| JST_ERR_STRING_BAD_ESCAPE_SEQUENCE | only ", \, /, b, f, n, r, t, u may be escaped |
| JST_ERR_STRING_CONTROL_CHAR_MUST_BE_ESCAPED | a control character has been found, it must be escaped |
| JST_ERR_SEPARATOR_EXPECTED_AFTER_TRUE | syntax error or 'true' |
| JST_ERR_SEPARATOR_EXPECTED_AFTER_FALSE | syntax error or 'false' |
| JST_ERR_SEPARATOR_EXPECTED_AFTER_NULL | syntax error or 'null' |
| JST_ERR_TRUE_EXPECTED | 'true' token was expected |
| JST_ERR_FALSE_EXPECTED | 'false' token was expected |
| JST_ERR_NULL_EXPECTED | 'null' token was expected |
| JST_ERR_NUMBER_EXPECTED | token is not a number |
| JST_ERR_COLON_EXPECTED | token is not a colon |
| JST_ERR_UNEXPECTED_TOKEN | unexpected token |
| JST_ERR_PATH_SYNTAX | Path syntax is (<name>|[<integer>])(.<name>|[<integer>])*. |
| JST_ERR_NOT_FOUND | JST_get() has no result. |
| JST_ERR_ARRAY_INDEX_OUT_OF_RANGE | index is out of range |
| JST_ERR_INTERRUPTED | JST_Visitor has returned false to interrupt the tree's iteration. |
Definition at line 108 of file jstools.h.
| enum JST_ValueType |
The JSON Value types.
| Enumerator | |
|---|---|
| JST_OBJECT | |
| JST_ARRAY | |
| JST_BOOLEAN | |
| JST_INTEGER | |
| JST_DOUBLE | |
| JST_STRING | |
| JST_NULL | |
Definition at line 57 of file jstools.h.
| JST_Error JST_add_item | ( | JST_Array * | array, |
| const JST_Element * | value | ||
| ) |
Definition at line 89 of file JST_update.c.
| JST_Error JST_add_property | ( | JST_Object * | object, |
| unsigned | index, | ||
| const char * | name, | ||
| const JST_Element * | value | ||
| ) |
Add a named-value pair to an object.
| object | the target object to modify |
| index | the property's rank, -1U to add at the end |
| name | the property's name |
| value | the property's value |
Definition at line 60 of file JST_update.c.
Definition at line 40 of file JST_delete.c.


| JST_Error JST_delete_array_item | ( | JST_ArrayItem * | array | ) |
Definition at line 31 of file JST_delete.c.


| JST_Error JST_delete_element | ( | JST_Element * | element | ) |
Definition at line 55 of file JST_delete.c.


| JST_Error JST_delete_object | ( | JST_Object * | object | ) |
Definition at line 15 of file JST_delete.c.


Definition at line 5 of file JST_delete.c.


| JST_Error JST_get | ( | const char * | jsonpath, |
| JST_Element * | root, | ||
| JST_Element ** | dest | ||
| ) |
Search an element by its path.
| jsonpath | syntax is (<name>|[<integer>])(.<name>|[<integer>])* |
| element | the root of the search |
| dest | an address of a pointer to the element found |
Definition at line 10 of file JST_get.c.
| JST_Error JST_load_from_file | ( | const char * | filepath, |
| JST_Element * | root, | ||
| JST_SyntaxError * | error | ||
| ) |
Reads the input file, allocates the node of the corresponding tree, than frees the input buffer.
| filepath | the file path |
| root | the root of the JSON tree |
| line | the last line number read, available in case of error |
| context | few characters before the error, available in case of error |
| ditsance | the offset of the error, in context |
Definition at line 573 of file JST_load.c.

| JST_Error JST_load_from_stream | ( | FILE * | stream, |
| JST_Element * | root, | ||
| JST_SyntaxError * | error | ||
| ) |
Reads the input stream, allocates the node of the corresponding tree, than frees the input buffer.
| stream | the character stream to read |
| root | the root of the JSON tree |
| line | the last line number read, available in case of error |
| context | few characters before the error, available in case of error |
| ditsance | the offset of the error, in context |
Definition at line 533 of file JST_load.c.

Definition at line 140 of file JST_update.c.

| JST_Error JST_remove_property | ( | JST_Object * | object, |
| const char * | name | ||
| ) |
Definition at line 124 of file JST_update.c.

| JST_Error JST_replace_item | ( | JST_Array * | array, |
| unsigned | index, | ||
| const JST_Element * | value | ||
| ) |
Definition at line 114 of file JST_update.c.
| JST_Error JST_save_to_file | ( | const char * | filepath, |
| const JST_Element * | root, | ||
| unsigned | indent | ||
| ) |
Save the JSON tree to a file, pretty-printed.
| filepath | the path of the target file |
| root | the root of the tree to save |
| indent | the amout of space to pretty print the tree. |
Definition at line 56 of file JST_save.c.

| JST_Error JST_save_to_file_compact | ( | const char * | filepath, |
| const JST_Element * | root | ||
| ) |
Save the JSON tree to a file, as a single line of text, without whitespaces.
| filepath | the path of the target file |
| root | the root of the tree to save |
Definition at line 120 of file JST_save.c.

| JST_Error JST_save_to_stream | ( | FILE * | stream, |
| const JST_Element * | root, | ||
| unsigned | indent | ||
| ) |
Save the JSON tree to a stream, pretty-printed.
| stream | the target stream. |
| root | the root of the tree to save. |
| indent | the amout of space to pretty print the tree. |
Definition at line 47 of file JST_save.c.

| JST_Error JST_save_to_stream_compact | ( | FILE * | stream, |
| const JST_Element * | root | ||
| ) |
Save the JSON tree to a stream, as a single line of text, without whitespaces.
| filepath | the path of the target file |
| root | the root of the tree to save |
Definition at line 112 of file JST_save.c.

| JST_Error JST_serialize | ( | JST_Element * | root, |
| char ** | dest, | ||
| unsigned | indent | ||
| ) |
Serialize the JSON tree to a string, pretty-printed.
| filepath | the path of the target file |
| root | the root of the tree to save |
| dest | a pointer to the char buffer allocated by this function, must be freed by the user |
| indent | the amout of space to pretty print the tree. When indent is negative, it means the JSON tree is printed with all the nodes on a single line. |
Definition at line 112 of file JST_serialize.c.
| JST_Error JST_serialize_compact | ( | JST_Element * | root, |
| char ** | dest | ||
| ) |
Serialize the JSON tree to a string as a single line of text, without whitespaces.
| filepath | the path of the target file |
| root | the root of the tree to save |
| dest | a pointer to the char buffer allocated by this function, must be freed by the user negative, it means the JSON tree is printed with all the nodes on a single line. |
Definition at line 227 of file JST_serialize.c.
| JST_Error JST_walk | ( | const JST_Element * | root, |
| JST_Visitor | visitor, | ||
| void * | user_context | ||
| ) |
Definition at line 45 of file JST_walk.c.
| const JST_Array JST_Array_Zero |
Constant defined to initialize safely a variable of type JST_Array.
Definition at line 16 of file JST_load.c.
| const JST_ArrayItem JST_ArrayItem_Zero |
Definition at line 20 of file JST_load.c.
| const JST_Element JST_Element_Zero |
Constant defined to initialize safely a variable of type JST_Element.
Definition at line 19 of file JST_load.c.
| const JST_Object JST_Object_Zero |
Constant defined to initialize safely a variable of type JST_Object.
Definition at line 17 of file JST_load.c.
| const JST_Pair JST_Pair_Zero |
Constant defined to initialize safely a variable of type JST_Pair.
Definition at line 21 of file JST_load.c.
| const JST_SyntaxError JST_SyntaxError_Zero |
Constant defined to initialize safely a variable of type JST_SyntaxError.
Definition at line 22 of file JST_load.c.
| const JST_Value JST_Value_Zero |
Constant defined to initialize safely a variable of type JST_Value.
Definition at line 18 of file JST_load.c.
1.8.13