diff --git a/doc/html/README_8md.html b/doc/html/README_8md.html new file mode 100644 index 0000000..b0f17f5 --- /dev/null +++ b/doc/html/README_8md.html @@ -0,0 +1,57 @@ + + +
+ + +
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
Internal methods for working with json_type_array objects. Although this is exposed by the json_object_get_array() method, it is not recommended for direct use. +More...
++Data Structures | |
struct | array_list |
+Macros | |
#define | ARRAY_LIST_DEFAULT_SIZE 32 |
+Typedefs | |
typedef void( | array_list_free_fn )(void *data) |
typedef struct array_list | array_list |
+Functions | |
struct array_list * | array_list_new (array_list_free_fn *free_fn) |
struct array_list * | array_list_new2 (array_list_free_fn *free_fn, int initial_size) |
void | array_list_free (struct array_list *al) |
void * | array_list_get_idx (struct array_list *al, size_t i) |
int | array_list_put_idx (struct array_list *al, size_t i, void *data) |
int | array_list_add (struct array_list *al, void *data) |
size_t | array_list_length (struct array_list *al) |
void | array_list_sort (struct array_list *arr, int(*compar)(const void *, const void *)) |
void * | array_list_bsearch (const void **key, struct array_list *arr, int(*compar)(const void *, const void *)) |
int | array_list_del_idx (struct array_list *arr, size_t idx, size_t count) |
int | array_list_shrink (struct array_list *arr, size_t empty_slots) |
Internal methods for working with json_type_array objects. Although this is exposed by the json_object_get_array() method, it is not recommended for direct use.
+#define ARRAY_LIST_DEFAULT_SIZE 32 | +
typedef struct array_list array_list | +
typedef void( array_list_free_fn)(void *data) | +
int array_list_add | +( | +struct array_list * | +al, | +
+ | + | void * | +data | +
+ | ) | ++ |
void* array_list_bsearch | +( | +const void ** | +key, | +
+ | + | struct array_list * | +arr, | +
+ | + | int(*)(const void *, const void *) | +compar | +
+ | ) | ++ |
int array_list_del_idx | +( | +struct array_list * | +arr, | +
+ | + | size_t | +idx, | +
+ | + | size_t | +count | +
+ | ) | ++ |
void array_list_free | +( | +struct array_list * | +al | ) | ++ |
void* array_list_get_idx | +( | +struct array_list * | +al, | +
+ | + | size_t | +i | +
+ | ) | ++ |
size_t array_list_length | +( | +struct array_list * | +al | ) | ++ |
+
|
+ +read | +
Allocate an array_list of the default size (32).
+
+
|
+ +read | +
Allocate an array_list of the desired size.
+If possible, the size should be chosen to closely match the actual number of elements expected to be used. If the exact size is unknown, there are tradeoffs to be made:
+int array_list_put_idx | +( | +struct array_list * | +al, | +
+ | + | size_t | +i, | +
+ | + | void * | +data | +
+ | ) | ++ |
int array_list_shrink | +( | +struct array_list * | +arr, | +
+ | + | size_t | +empty_slots | +
+ | ) | ++ |
Shrink the array list to just enough to fit the number of elements in it, plus empty_slots.
+ +void array_list_sort | +( | +struct array_list * | +arr, | +
+ | + | int(*)(const void *, const void *) | +compar | +
+ | ) | ++ |
+ json-c
+ 0.16
+
+ |
+
| json_object_iterator | lh_table | |||
json_tokener |
| ||||
array_list | json_tokener_srec | ||||
|
| printbuf | |||
json_object_iter | lh_entry | ||||
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+Files | |
file | json.h |
A convenience header that may be included instead of other individual ones. | |
+ json-c
+ 0.16
+
+ |
+
![]() ![]() | |
![]() ![]() ![]() | A convenience header that may be included instead of other individual ones |
![]() ![]() | Internal methods for working with json_type_array objects. Although this is exposed by the json_object_get_array() method, it is not recommended for direct use |
![]() ![]() | Methods for retrieving the json-c version |
![]() ![]() | Do not use, json-c internal, may be changed or removed at any time |
![]() ![]() | Core json-c API. Start here, or with json_tokener.h |
![]() ![]() | An API for iterating over json_type_object objects, styled to be familiar to C++ programmers. Unlike json_object_object_foreach() and json_object_object_foreachC(), this avoids the need to expose json-c internals like lh_entry |
![]() ![]() | JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree |
![]() ![]() | Methods to parse an input string into a tree of json_object objects |
![]() ![]() | Basic types used in a few places in json-c, but you should include "json_object.h" instead |
![]() ![]() | Miscllaneous utility functions and macros |
![]() ![]() | Methods for walking a tree of objects |
![]() ![]() | Internal methods for working with json_type_object objects. Although this is exposed by the json_object_get_object() function and within the json_object_iter type, it is not recommended for direct use |
![]() ![]() | Internal string buffer handling. Unless you're writing a json_object_to_json_string_fn implementation for use with json_object_set_serializer() direct use of this is not recommended |
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
json-c
JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects. It aims to conform to RFC 7159.
+Skip down to Using json-c or check out the API docs, if you already have json-c installed and ready to use.
+Home page for json-c: https://github.com/json-c/json-c/wiki
+Build Status
+Test Status
+git
, gcc
and cmake
If you already have json-c installed, see Linking to `libjson-c` for how to build and link your program against it.
+gcc
, clang
, or another C compilercmake>=2.8
, >=3.16
recommended, cmake=>3.1
for testsTo generate docs you'll also need:
+doxygen>=1.8.13
If you are on a relatively modern system, you'll likely be able to install the prerequisites using your OS's packaging system.
+sudo apt install git +sudo apt install cmake +sudo apt install doxygen # optional +sudo apt install valgrind # optional +
json-c
GitHub repo: https://github.com/json-c/json-c
$ git clone https://github.com/json-c/json-c.git +$ mkdir json-c-build +$ cd json-c-build +$ cmake ../json-c # See CMake section below for custom arguments +
Note: it's also possible to put your build directory inside the json-c source directory, or even not use a separate build directory at all, but certain things might not work quite right (notably, make distcheck
)
Then:
+$ make +$ make test +$ make USE_VALGRIND=0 test # optionally skip using valgrind +$ make install +
The library documentation can be generated directly from the source code using Doxygen tool:
+# in build directory +make doc +google-chrome doc/html/index.html +
The json-c library is built with CMake, which can take a few options.
+Variable | Type | Description |
---|---|---|
CMAKE_INSTALL_PREFIX | String | The install location. |
CMAKE_BUILD_TYPE | String | Defaults to "debug". |
BUILD_SHARED_LIBS | Bool | The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library only. |
BUILD_STATIC_LIBS | Bool | The default build generates a static (lib/a) library. Set this to OFF to create a shared library only. |
DISABLE_STATIC_FPIC | Bool | The default builds position independent code. Set this to OFF to create a shared library only. |
DISABLE_BSYMBOLIC | Bool | Disable use of -Bsymbolic-functions. |
DISABLE_THREAD_LOCAL_STORAGE | Bool | Disable use of Thread-Local Storage (HAVE___THREAD). |
DISABLE_WERROR | Bool | Disable use of -Werror. |
ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed. |
ENABLE_THREADING | Bool | Enable partial threading support. |
OVERRIDE_GET_RANDOM_SEED | String | A block of code to use instead of the default implementation of json_c_get_random_seed(), e.g. on embedded platforms where not even the fallback to time() works. Must be a single line. |
Pass these options as -D
on CMake's command-line.
# build a static library only +cmake -DBUILD_SHARED_LIBS=OFF .. +
Although json-c does not support fully multi-threaded access to object trees, it has some code to help make its use in threaded programs a bit safer. Currently, this is limited to using atomic operations for json_object_get() and json_object_put().
+Since this may have a performance impact, of at least 3x slower according to https://stackoverflow.com/a/11609063, it is disabled by default. You may turn it on by adjusting your cmake command with: -DENABLE_THREADING=ON
+Separately, the default hash function used for object field keys, lh_char_hash, uses a compare-and-swap operation to ensure the random seed is only generated once. Because this is a one-time operation, it is always compiled in when the compare-and-swap operation is available.
+For those familiar with the old autoconf/autogen.sh/configure method, there is a cmake-configure
wrapper script to ease the transition to cmake.
mkdir build +cd build +../cmake-configure --prefix=/some/install/path +make +
cmake-configure can take a few options.
+options | Description |
---|---|
prefix=PREFIX | install architecture-independent files in PREFIX |
enable-threading | Enable code to support partly multi-threaded use |
enable-rdrand | Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms. |
enable-shared | build shared libraries [default=yes] |
enable-static | build static libraries [default=yes] |
disable-Bsymbolic | Avoid linking with -Bsymbolic-function |
disable-werror | Avoid treating compiler warnings as fatal errors |
By default, if valgrind is available running tests uses it. That can slow the tests down considerably, so to disable it use:
+export USE_VALGRIND=0 +
To run tests a separate build directory is recommended:
+mkdir build-test +cd build-test +# VALGRIND=1 causes -DVALGRIND=1 to be passed when compiling code +# which uses slightly slower, but valgrind-safe code. +VALGRIND=1 cmake .. +make + +make test +# By default, if valgrind is available running tests uses it. +make USE_VALGRIND=0 test # optionally skip using valgrind +
If a test fails, check Testing/Temporary/LastTest.log
, tests/testSubDir/${testname}/${testname}.vg.out
, and other similar files. If there is insufficient output try:
VERBOSE=1 CTEST_OUTPUT_ON_FAILURE=1 make test +
or
+JSONC_TEST_TRACE=1 make test +
and check the log files again.
+vcpkg
You can download and install JSON-C using the vcpkg dependency manager:
+git clone https://github.com/Microsoft/vcpkg.git +cd vcpkg +./bootstrap-vcpkg.sh +./vcpkg integrate install +vcpkg install json-c +
The JSON-C port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.
+libjson-c
If your system has pkgconfig
, then you can just add this to your makefile
:
CFLAGS += $(shell pkg-config --cflags json-c) +LDFLAGS += $(shell pkg-config --libs json-c) +
Without pkgconfig
, you might do something like this:
JSON_C_DIR=/path/to/json_c/install +CFLAGS += -I$(JSON_C_DIR)/include/json-c +# Or to use lines like: #include <json-c/json_object.h> +#CFLAGS += -I$(JSON_C_DIR)/include +LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c +
If your project uses cmake:
+Add to your CMakeLists.txt file:
+find_package(json-c CONFIG) target_link_libraries(${PROJECT_NAME} PRIVATE json-c::json-c)
+Then you might run in your project:
+cd build cmake -DCMAKE_PREFIX_PATH=/path/to/json_c/install/lib64/cmake ..
+To use json-c you can either include json.h, or preferably, one of the following more specific header files:
+json_object_object_foreach()
in json_object.h)For a full list of headers see files.html
+The primary type in json-c is json_object. It describes a reference counted tree of json objects which are created by either parsing text with a json_tokener (i.e. json_tokener_parse_ex()
), or by creating (with json_object_new_object()
, json_object_new_int()
, etc...) and adding (with json_object_object_add()
, json_object_array_add()
, etc...) them individually. Typically, every object in the tree will have one reference, from its parent. When you are done with the tree of objects, you call json_object_put() on just the root object to free it, which recurses down through any child objects calling json_object_put() on each one of those in turn.
You can get a reference to a single child (json_object_object_get()
or json_object_array_get_idx()
) and use that object as long as its parent is valid. If you need a child object to live longer than its parent, you can increment the child's refcount (json_object_get()
) to allow it to survive the parent being freed or it being removed from its parent (json_object_object_del()
or json_object_array_del_idx()
)
When parsing text, the json_tokener object is independent from the json_object that it returns. It can be allocated (json_tokener_new()
) used one or multiple times (json_tokener_parse_ex()
, and freed (json_tokener_free()
) while the json_object objects live on.
A json_object tree can be serialized back into a string with json_object_to_json_string_ext()
. The string that is returned is only valid until the next "to_json_string" call on that same object. Also, it is freed when the json_object is freed.
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
t |
+ json-c
+ 0.16
+
+ |
+
A convenience header that may be included instead of other individual ones. +More...
+A convenience header that may be included instead of other individual ones.
+
+ json-c
+ 0.16
+
+ |
+
Methods for retrieving the json-c version. +More...
++Macros | |
#define | JSON_C_MAJOR_VERSION 0 |
#define | JSON_C_MINOR_VERSION 16 |
#define | JSON_C_MICRO_VERSION 0 |
#define | JSON_C_VERSION_NUM ((JSON_C_MAJOR_VERSION << 16) | (JSON_C_MINOR_VERSION << 8) | JSON_C_MICRO_VERSION) |
#define | JSON_C_VERSION "0.16" |
#define | JSON_EXPORT extern |
+Functions | |
JSON_EXPORT const char * | json_c_version (void) |
JSON_EXPORT int | json_c_version_num (void) |
Methods for retrieving the json-c version.
+#define JSON_C_MAJOR_VERSION 0 | +
#define JSON_C_MICRO_VERSION 0 | +
#define JSON_C_MINOR_VERSION 16 | +
#define JSON_C_VERSION "0.16" | +
#define JSON_C_VERSION_NUM ((JSON_C_MAJOR_VERSION << 16) | (JSON_C_MINOR_VERSION << 8) | JSON_C_MICRO_VERSION) | +
#define JSON_EXPORT extern | +
JSON_EXPORT const char* json_c_version | +( | +void | +) | ++ |
JSON_EXPORT int json_c_version_num | +( | +void | +) | ++ |
The json-c version encoded into an int, with the low order 8 bits being the micro version, the next higher 8 bits being the minor version and the next higher 8 bits being the major version. For example, 7.12.99 would be 0x00070B63.
+
+ json-c
+ 0.16
+
+ |
+
Do not use, json-c internal, may be changed or removed at any time. +More...
++Macros | |
#define | PRId64 "I64d" |
#define | SCNd64 "I64d" |
#define | PRIu64 "I64u" |
Do not use, json-c internal, may be changed or removed at any time.
+#define PRId64 "I64d" | +
#define PRIu64 "I64u" | +
#define SCNd64 "I64d" | +
+ json-c
+ 0.16
+
+ |
+
Core json-c API. Start here, or with json_tokener.h. +More...
++Macros | |
#define | JSON_C_CONST_FUNCTION(func) func |
#define | JSON_OBJECT_DEF_HASH_ENTRIES 16 |
#define | JSON_C_TO_STRING_PLAIN 0 |
#define | JSON_C_TO_STRING_SPACED (1 << 0) |
#define | JSON_C_TO_STRING_PRETTY (1 << 1) |
#define | JSON_C_TO_STRING_PRETTY_TAB (1 << 3) |
#define | JSON_C_TO_STRING_NOZERO (1 << 2) |
#define | JSON_C_TO_STRING_NOSLASHESCAPE (1 << 4) |
#define | JSON_C_OBJECT_ADD_KEY_IS_NEW (1 << 1) |
#define | JSON_C_OBJECT_ADD_CONSTANT_KEY (1 << 2) |
#define | JSON_C_OBJECT_KEY_IS_CONSTANT JSON_C_OBJECT_ADD_CONSTANT_KEY |
#define | JSON_C_OPTION_GLOBAL (0) |
#define | JSON_C_OPTION_THREAD (1) |
#define | json_object_object_foreach(obj, key, val) |
#define | json_object_object_foreachC(obj, iter) |
+Typedefs | |
typedef int( | json_c_shallow_copy_fn )(json_object *src, json_object *parent, const char *key, size_t index, json_object **dst) |
Core json-c API. Start here, or with json_tokener.h.
+#define JSON_C_CONST_FUNCTION | +( | ++ | func | ) | +func | +
#define JSON_C_OBJECT_ADD_CONSTANT_KEY (1 << 2) | +
A flag for the json_object_object_add_ex function which flags the key as being constant memory. This means that the key will NOT be copied via strdup(), resulting in a potentially huge performance win (malloc, strdup and free are usually performance hogs). It is acceptable to use this flag for keys in non-constant memory blocks if the caller ensure that the memory holding the key lives longer than the corresponding json object. However, this is somewhat dangerous and should only be done if really justified. The general use-case for this flag is cases where the key is given as a real constant value in the function call, e.g. as in json_object_object_add_ex(obj, "ip", json, JSON_C_OBJECT_ADD_CONSTANT_KEY);
+ +#define JSON_C_OBJECT_ADD_KEY_IS_NEW (1 << 1) | +
A flag for the json_object_object_add_ex function which causes the value to be added without a check if it already exists. Note: it is the responsibility of the caller to ensure that no key is added multiple times. If this is done, results are unpredictable. While this option is somewhat dangerous, it permits potentially large performance savings in code that knows for sure the key values are unique (e.g. because the code adds a well-known set of constant key values).
+ +#define JSON_C_OBJECT_KEY_IS_CONSTANT JSON_C_OBJECT_ADD_CONSTANT_KEY | +
This flag is an alias to JSON_C_OBJECT_ADD_CONSTANT_KEY. Historically, this flag was used first and the new name JSON_C_OBJECT_ADD_CONSTANT_KEY was introduced for version 0.16.00 in order to have regular naming. Use of this flag is now legacy.
+ +#define JSON_C_OPTION_GLOBAL (0) | +
Set the global value of an option, which will apply to all current and future threads that have not set a thread-local value.
+ + +#define JSON_C_OPTION_THREAD (1) | +
Set a thread-local value of an option, overriding the global value. This will fail if json-c is not compiled with threading enabled, and with the __thread specifier (or equivalent) available.
+ + +#define JSON_C_TO_STRING_NOSLASHESCAPE (1 << 4) | +
Don't escape forward slashes.
+ +#define JSON_C_TO_STRING_NOZERO (1 << 2) | +
A flag to drop trailing zero for float values
+ +#define JSON_C_TO_STRING_PLAIN 0 | +
A flag for the json_object_to_json_string_ext() and json_object_to_file_ext() functions which causes the output to have no extra whitespace or formatting applied.
+ +#define JSON_C_TO_STRING_PRETTY (1 << 1) | +
A flag for the json_object_to_json_string_ext() and json_object_to_file_ext() functions which causes the output to be formatted.
+See the "Two Space Tab" option at https://jsonformatter.curiousconcept.com/ for an example of the format.
+ +#define JSON_C_TO_STRING_PRETTY_TAB (1 << 3) | +
A flag for the json_object_to_json_string_ext() and json_object_to_file_ext() functions which causes the output to be formatted.
+Instead of a "Two Space Tab" this gives a single tab character.
+ +#define JSON_C_TO_STRING_SPACED (1 << 0) | +
A flag for the json_object_to_json_string_ext() and json_object_to_file_ext() functions which causes the output to have minimal whitespace inserted to make things slightly more readable.
+ +#define JSON_OBJECT_DEF_HASH_ENTRIES 16 | +
#define json_object_object_foreach | +( | ++ | obj, | +
+ | + | + | key, | +
+ | + | + | val | +
+ | ) | ++ |
Iterate through all keys and values of an object.
+Adding keys to the object while iterating is NOT allowed.
+Deleting an existing key, or replacing an existing key with a new value IS allowed.
+obj | the json_object instance |
key | the local name for the char* key variable defined in the body |
val | the local name for the json_object* object variable defined in the body |
#define json_object_object_foreachC | +( | ++ | obj, | +
+ | + | + | iter | +
+ | ) | ++ |
Iterate through all keys and values of an object (ANSI C Safe)
+obj | the json_object instance |
iter | the object iterator, use type json_object_iter |
typedef int( json_c_shallow_copy_fn)(json_object *src, json_object *parent, const char *key, size_t index, json_object **dst) | +
Perform a shallow copy of src into *dst as part of an overall json_object_deep_copy().
+If src is part of a containing object or array, parent will be non-NULL, and key or index will be provided. When shallow_copy is called *dst will be NULL, and must be non-NULL when it returns. src will never be NULL.
+If shallow_copy sets the serializer on an object, return 2 to indicate to json_object_deep_copy that it should not attempt to use the standard userdata copy function.
+size_t json_c_object_sizeof | +( | +void | +) | ++ |
Get the sizeof (struct json_object).
+JSON_EXPORT int json_c_set_serialization_double_format | +( | +const char * | +double_format, | +
+ | + | int | +global_or_thread | +
+ | ) | ++ |
Set a global or thread-local json-c option, depending on whether JSON_C_OPTION_GLOBAL or JSON_C_OPTION_THREAD is passed. Thread-local options default to undefined, and inherit from the global value, even if the global value is changed after the thread is created. Attempting to set thread-local options when threading is not compiled in will result in an error. Be sure to check the return value.
+double_format is a "%g" printf format, such as "%.20g"
+JSON_EXPORT int json_object_array_add | +( | +struct json_object * | +obj, | +
+ | + | struct json_object * | +val | +
+ | ) | ++ |
Add an element to the end of a json_object of type json_type_array
+The reference count will not be incremented. This is to make adding fields to objects in code more compact. If you want to retain a reference to an added object you must wrap the passed object with json_object_get
+obj | the json_object instance |
val | the json_object to be added |
+
|
+ +read | +
Binary search a sorted array for a specified key object.
+It depends on your compare function what's sufficient as a key. Usually you create some dummy object with the parameter compared in it, to identify the right item you're actually looking for.
+key | a dummy json_object with the right key |
jso | the array object we're searching |
sort_fn | the sort/compare function |
JSON_EXPORT int json_object_array_del_idx | +( | +struct json_object * | +obj, | +
+ | + | size_t | +idx, | +
+ | + | size_t | +count | +
+ | ) | ++ |
Delete an elements from a specified index in an array (a json_object of type json_type_array)
+The reference count will be decremented for each of the deleted objects. If there are no more owners of an element that is being deleted, then the value is freed. Otherwise, the reference to the value will remain in memory.
+obj | the json_object instance |
idx | the index to start deleting elements at |
count | the number of elements to delete |
+
|
+ +read | +
Get the element at specified index of array obj
(which must be a json_object of type json_type_array)
No reference counts will be changed, and ownership of the returned object remains with obj
. See json_object_object_get() for additional implications of this behavior.
Calling this with anything other than a json_type_array will trigger an assert.
+obj | the json_object instance |
idx | the index to get the element at |
JSON_EXPORT size_t json_object_array_length | +( | +const struct json_object * | +obj | ) | ++ |
Get the length of a json_object of type json_type_array
+obj | the json_object instance |
JSON_EXPORT int json_object_array_put_idx | +( | +struct json_object * | +obj, | +
+ | + | size_t | +idx, | +
+ | + | struct json_object * | +val | +
+ | ) | ++ |
Insert or replace an element at a specified index in an array (a json_object of type json_type_array)
+The reference count will not be incremented. This is to make adding fields to objects in code more compact. If you want to retain a reference to an added object you must wrap the passed object with json_object_get
+The reference count of a replaced object will be decremented.
+The array size will be automatically be expanded to the size of the index if the index is larger than the current size.
+obj | the json_object instance |
idx | the index to insert the element at |
val | the json_object to be added |
JSON_EXPORT int json_object_array_shrink | +( | +struct json_object * | +jso, | +
+ | + | int | +empty_slots | +
+ | ) | ++ |
Shrink the internal memory allocation of the array to just enough to fit the number of elements in it, plus empty_slots.
+jso | the json_object instance, must be json_type_array |
empty_slots | the number of empty slots to leave allocated |
JSON_EXPORT void json_object_array_sort | +( | +struct json_object * | +jso, | +
+ | + | int(*)(const void *, const void *) | +sort_fn | +
+ | ) | ++ |
Sorts the elements of jso of type json_type_array
+Pointers to the json_object pointers will be passed as the two arguments to sort_fn
+jso | the json_object instance |
sort_fn | a sorting function |
JSON_EXPORT int json_object_deep_copy | +( | +struct json_object * | +src, | +
+ | + | struct json_object ** | +dst, | +
+ | + | json_c_shallow_copy_fn * | +shallow_copy | +
+ | ) | ++ |
Copy the contents of the JSON object. The destination object must be initialized to NULL, to make sure this function won't overwrite an existing JSON object.
+This does roughly the same thing as json_tokener_parse(json_object_get_string(src))
.
src | source JSON object whose contents will be copied |
dst | pointer to the destination object where the contents of src ; make sure this pointer is initialized to NULL |
shallow_copy | an optional function to copy individual objects, needed when custom serializers are in use. See also json_object set_serializer. |
JSON_EXPORT int json_object_double_to_json_string | +( | +struct json_object * | +jso, | +
+ | + | struct printbuf * | +pb, | +
+ | + | int | +level, | +
+ | + | int | +flags | +
+ | ) | ++ |
Serialize a json_object of type json_type_double to a string.
+This function isn't meant to be called directly. Instead, you can set a custom format string for the serialization of this double using the following call (where "%.17g" actually is the default):
+jso | The json_type_double object that is serialized. |
pb | The destination buffer. |
level | Ignored. |
flags | Ignored. |
JSON_EXPORT int json_object_equal | +( | +struct json_object * | +obj1, | +
+ | + | struct json_object * | +obj2 | +
+ | ) | ++ |
Check if two json_object's are equal
+If the passed objects are equal 1 will be returned. Equality is defined as follows:
+obj1 | the first json_object instance |
obj2 | the second json_object instance |
+
|
+ +read | +
Increment the reference count of json_object, thereby taking ownership of it.
+Cases where you might need to increase the refcount include:
+json_object_object_get()
or json_object_array_get_idx()
) beyond the lifetime of the parent object.json_object_object_del()
or json_object_array_del_idx()
)json_object_put()
) when they're done.obj | the json_object instance |
+
|
+ +read | +
Get the arraylist of a json_object of type json_type_array
+obj | the json_object instance |
JSON_EXPORT json_bool json_object_get_boolean | +( | +const struct json_object * | +obj | ) | ++ |
Get the json_bool value of a json_object
+The type is coerced to a json_bool if the passed object is not a json_bool. integer and double objects will return 0 if there value is zero or 1 otherwise. If the passed object is a string it will return 1 if it has a non zero length. If any other object type is passed 0 will be returned, even non-empty json_type_array and json_type_object objects.
+obj | the json_object instance |
JSON_EXPORT double json_object_get_double | +( | +const struct json_object * | +obj | ) | ++ |
Get the double floating point value of a json_object
+The type is coerced to a double if the passed object is not a double. integer objects will return their double conversion. Strings will be parsed as a double. If no conversion exists then 0.0 is returned and errno is set to EINVAL. null is equivalent to 0 (no error values set)
+If the value is too big to fit in a double, then the value is set to the closest infinity with errno set to ERANGE. If strings cannot be converted to their double value, then EINVAL is set & NaN is returned.
+Arrays of length 0 are interpreted as 0 (with no error flags set). Arrays of length 1 are effectively cast to the equivalent object and converted using the above rules. All other arrays set the error to EINVAL & return NaN.
+NOTE: Set errno to 0 directly before a call to this function to determine whether or not conversion was successful (it does not clear the value for you).
+obj | the json_object instance |
JSON_EXPORT int32_t json_object_get_int | +( | +const struct json_object * | +obj | ) | ++ |
Get the int value of a json_object
+The type is coerced to a int if the passed object is not a int. double objects will return their integer conversion. Strings will be parsed as an integer. If no conversion exists then 0 is returned and errno is set to EINVAL. null is equivalent to 0 (no error values set)
+Note that integers are stored internally as 64-bit values. If the value of too big or too small to fit into 32-bit, INT32_MAX or INT32_MIN are returned, respectively.
+obj | the json_object instance |
JSON_EXPORT int64_t json_object_get_int64 | +( | +const struct json_object * | +obj | ) | ++ |
Get the int value of a json_object
+The type is coerced to a int64 if the passed object is not a int64. double objects will return their int64 conversion. Strings will be parsed as an int64. If no conversion exists then 0 is returned.
+NOTE: Set errno to 0 directly before a call to this function to determine whether or not conversion was successful (it does not clear the value for you).
+obj | the json_object instance |
+
|
+ +read | +
Get the hashtable of a json_object of type json_type_object
+obj | the json_object instance |
JSON_EXPORT const char* json_object_get_string | +( | +struct json_object * | +obj | ) | ++ |
Get the string value of a json_object
+If the passed object is of type json_type_null (i.e. obj == NULL), NULL is returned.
+If the passed object of type json_type_string, the string contents are returned.
+Otherwise the JSON representation of the object is returned.
+The returned string memory is managed by the json_object and will be freed when the reference count of the json_object drops to zero.
+obj | the json_object instance |
JSON_EXPORT int json_object_get_string_len | +( | +const struct json_object * | +obj | ) | ++ |
Get the string length of a json_object
+If the passed object is not of type json_type_string then zero will be returned.
+obj | the json_object instance |
JSON_EXPORT enum json_type json_object_get_type | +( | +const struct json_object * | +obj | ) | ++ |
Get the type of the json_object. See also json_type_to_name() to turn this into a string suitable, for instance, for logging.
+obj | the json_object instance |
JSON_EXPORT uint64_t json_object_get_uint64 | +( | +const struct json_object * | +obj | ) | ++ |
Get the uint value of a json_object
+The type is coerced to a uint64 if the passed object is not a uint64. double objects will return their uint64 conversion. Strings will be parsed as an uint64. If no conversion exists then 0 is returned.
+NOTE: Set errno to 0 directly before a call to this function to determine whether or not conversion was successful (it does not clear the value for you).
+obj | the json_object instance |
JSON_EXPORT void* json_object_get_userdata | +( | +json_object * | +jso | ) | ++ |
Returns the userdata set by json_object_set_userdata() or json_object_set_serializer()
+jso | the object to return the userdata for |
JSON_EXPORT int json_object_int_inc | +( | +struct json_object * | +obj, | +
+ | + | int64_t | +val | +
+ | ) | ++ |
Increment a json_type_int object by the given amount, which may be negative.
+If the type of obj is not json_type_int then 0 is returned with no further action taken. If the addition would result in a overflow, the object value is set to INT64_MAX. If the addition would result in a underflow, the object value is set to INT64_MIN. Neither overflow nor underflow affect the return value.
+obj | the json_object instance |
val | the value to add |
JSON_EXPORT int json_object_is_type | +( | +const struct json_object * | +obj, | +
+ | + | enum json_type | +type | +
+ | ) | ++ |
Check if the json_object is of a given type
+obj | the json_object instance |
type | one of: json_type_null (i.e. obj == NULL), json_type_boolean, json_type_double, json_type_int, json_type_object, json_type_array, json_type_string |
+
|
+ +read | +
Create a new empty json_object of type json_type_array with 32 slots allocated. If you know the array size you'll need ahead of time, use json_object_new_array_ext() instead.
+ +
+
|
+ +read | +
Create a new empty json_object of type json_type_array with the desired number of slots allocated.
+initial_size | the number of slots to allocate |
+
|
+ +read | +
Create a new empty json_object of type json_type_boolean
+b | a json_bool 1 or 0 |
+
|
+ +read | +
Create a new empty json_object of type json_type_double
+d | the double |
+
|
+ +read | +
Create a new json_object of type json_type_double, using the exact serialized representation of the value.
+This allows for numbers that would otherwise get displayed inefficiently (e.g. 12.3 => "12.300000000000001") to be serialized with the more convenient form.
+Notes:
+This is used by json_tokener_parse_ex() to allow for an exact re-serialization of a parsed object.
+The userdata field is used to store the string representation, so it can't be used for other data if this function is used.
+A roughly equivalent sequence of calls, with the difference being that the serialization function won't be reset by json_object_set_double(), is:
+d | the numeric value of the double. |
ds | the string representation of the double. This will be copied. |
+
|
+ +read | +
Create a new empty json_object of type json_type_int Note that values are stored as 64-bit values internally. To ensure the full range is maintained, use json_object_new_int64 instead.
+i | the integer |
+
|
+ +read | +
Create a new empty json_object of type json_type_int
+i | the integer |
+
|
+ +read | +
This method exists only to provide a complementary function along the lines of the other json_object_new_* functions. It always returns NULL, and it is entirely acceptable to simply use NULL directly.
+ +
+
|
+ +read | +
Create a new empty object with a reference count of 1. The caller of this object initially has sole ownership. Remember, when using json_object_object_add or json_object_array_put_idx, ownership will transfer to the object/array. Call json_object_get if you want to maintain shared ownership or also add this object as a child of multiple objects or arrays. Any ownerships you acquired but did not transfer must be released through json_object_put.
+
+
|
+ +read | +
Create a new empty json_object of type json_type_string
+A copy of the string is made and the memory is managed by the json_object
+s | the string |
+
|
+ +read | +
Create a new empty json_object of type json_type_string and allocate len characters for the new string.
+A copy of the string is made and the memory is managed by the json_object
+s | the string |
len | max length of the new string |
+
|
+ +read | +
Create a new empty json_object of type json_type_uint
+i | the integer |
JSON_EXPORT int json_object_object_add | +( | +struct json_object * | +obj, | +
+ | + | const char * | +key, | +
+ | + | struct json_object * | +val | +
+ | ) | ++ |
Add an object field to a json_object of type json_type_object
+The reference count of val
will not be incremented, in effect transferring ownership that object to obj
, and thus val
will be freed when obj
is. (i.e. through json_object_put(obj)
)
If you want to retain a reference to the added object, independent of the lifetime of obj, you must increment the refcount with json_object_get(val)
(and later release it with json_object_put()).
Since ownership transfers to obj
, you must make sure that you do in fact have ownership over val
. For instance, json_object_new_object() will give you ownership until you transfer it, whereas json_object_object_get() does not.
Any previous object stored under key
in obj
will have its refcount decremented, and be freed normally if that drops to zero.
obj | the json_object instance |
key | the object field name (a private copy will be duplicated) |
val | a json_object or NULL member to associate with the given field |
0
is returned. On error, a negative value is returned. JSON_EXPORT int json_object_object_add_ex | +( | +struct json_object * | +obj, | +
+ | + | const char *const | +key, | +
+ | + | struct json_object *const | +val, | +
+ | + | const unsigned | +opts | +
+ | ) | ++ |
Add an object field to a json_object of type json_type_object
+The semantics are identical to json_object_object_add, except that an additional flag fields gives you more control over some detail aspects of processing. See the description of JSON_C_OBJECT_ADD_* flags for more details.
+obj | the json_object instance |
key | the object field name (a private copy will be duplicated) |
val | a json_object or NULL member to associate with the given field |
opts | process-modifying options. To specify multiple options, use (OPT1|OPT2) |
JSON_EXPORT void json_object_object_del | +( | +struct json_object * | +obj, | +
+ | + | const char * | +key | +
+ | ) | ++ |
Delete the given json_object field
+The reference count will be decremented for the deleted object. If there are no more owners of the value represented by this key, then the value is freed. Otherwise, the reference to the value will remain in memory.
+obj | the json_object instance |
key | the object field name |
+
|
+ +read | +
Get the json_object associate with a given object field. Deprecated/discouraged: used json_object_object_get_ex instead.
+This returns NULL if the field is found but its value is null, or if the field is not found, or if obj is not a json_type_object. If you need to distinguish between these cases, use json_object_object_get_ex().
+No reference counts will be changed. There is no need to manually adjust reference counts through the json_object_put/json_object_get methods unless you need to have the child (value) reference maintain a different lifetime than the owning parent (obj). Ownership of the returned value is retained by obj (do not do json_object_put unless you have done a json_object_get). If you delete the value from obj (json_object_object_del) and wish to access the returned reference afterwards, make sure you have first gotten shared ownership through json_object_get (& don't forget to do a json_object_put or transfer ownership to prevent a memory leak).
+obj | the json_object instance |
key | the object field name |
JSON_EXPORT json_bool json_object_object_get_ex | +( | +const struct json_object * | +obj, | +
+ | + | const char * | +key, | +
+ | + | struct json_object ** | +value | +
+ | ) | ++ |
Get the json_object associated with a given object field.
+This returns true if the key is found, false in all other cases (including if obj isn't a json_type_object).
+No reference counts will be changed. There is no need to manually adjust reference counts through the json_object_put/json_object_get methods unless you need to have the child (value) reference maintain a different lifetime than the owning parent (obj). Ownership of value is retained by obj.
+obj | the json_object instance |
key | the object field name |
value | a pointer where to store a reference to the json_object associated with the given field name. |
It is safe to pass a NULL value.
+JSON_EXPORT int json_object_object_length | +( | +const struct json_object * | +obj | ) | ++ |
Get the size of an object in terms of the number of fields it has.
+obj | the json_object whose length to return |
JSON_EXPORT int json_object_put | +( | +struct json_object * | +obj | ) | ++ |
Decrement the reference count of json_object and free if it reaches zero.
+You must have ownership of obj prior to doing this or you will cause an imbalance in the reference count, leading to a classic use-after-free bug. In particular, you normally do not need to call json_object_put()
on the json_object returned by json_object_object_get()
or json_object_array_get_idx()
.
Just like after calling free()
on a block of memory, you must not use obj
after calling json_object_put()
on it or any object that it is a member of (unless you know you've called json_object_get(obj)
to explicitly increment the refcount).
NULL may be passed, which which case this is a no-op.
+obj | the json_object instance |
JSON_EXPORT int json_object_set_boolean | +( | +struct json_object * | +obj, | +
+ | + | json_bool | +new_value | +
+ | ) | ++ |
Set the json_bool value of a json_object
+The type of obj is checked to be a json_type_boolean and 0 is returned if it is not without any further actions. If type of obj is json_type_boolean the object value is changed to new_value
+obj | the json_object instance |
new_value | the value to be set |
JSON_EXPORT int json_object_set_double | +( | +struct json_object * | +obj, | +
+ | + | double | +new_value | +
+ | ) | ++ |
Set the double value of a json_object
+The type of obj is checked to be a json_type_double and 0 is returned if it is not without any further actions. If type of obj is json_type_double the object value is changed to new_value
+If the object was created with json_object_new_double_s(), the serialization function is reset to the default and the cached serialized value is cleared.
+obj | the json_object instance |
new_value | the value to be set |
JSON_EXPORT int json_object_set_int | +( | +struct json_object * | +obj, | +
+ | + | int | +new_value | +
+ | ) | ++ |
Set the int value of a json_object
+The type of obj is checked to be a json_type_int and 0 is returned if it is not without any further actions. If type of obj is json_type_int the object value is changed to new_value
+obj | the json_object instance |
new_value | the value to be set |
JSON_EXPORT int json_object_set_int64 | +( | +struct json_object * | +obj, | +
+ | + | int64_t | +new_value | +
+ | ) | ++ |
Set the int64_t value of a json_object
+The type of obj is checked to be a json_type_int and 0 is returned if it is not without any further actions. If type of obj is json_type_int the object value is changed to new_value
+obj | the json_object instance |
new_value | the value to be set |
JSON_EXPORT void json_object_set_serializer | +( | +json_object * | +jso, | +
+ | + | json_object_to_json_string_fn * | +to_string_func, | +
+ | + | void * | +userdata, | +
+ | + | json_object_delete_fn * | +user_delete | +
+ | ) | ++ |
Set a custom serialization function to be used when this particular object is converted to a string by json_object_to_json_string.
+If custom userdata is already set on this object, any existing user_delete function is called before the new one is set.
+If to_string_func is NULL the default behaviour is reset (but the userdata and user_delete fields are still set).
+The userdata parameter is optional and may be passed as NULL. It can be used to provide additional data for to_string_func to use. This parameter may be NULL even if user_delete is non-NULL.
+The user_delete parameter is optional and may be passed as NULL, even if the userdata parameter is non-NULL. It will be called just before the json_object is deleted, after it's reference count goes to zero (see json_object_put()). If this is not provided, it is up to the caller to free the userdata at an appropriate time. (i.e. after the json_object is deleted)
+Note that the userdata is the same as set by json_object_set_userdata(), so care must be taken not to overwrite the value when both a custom serializer and json_object_set_userdata() are used.
+jso | the object to customize |
to_string_func | the custom serialization function |
userdata | an optional opaque cookie |
user_delete | an optional function from freeing userdata |
JSON_EXPORT int json_object_set_string | +( | +json_object * | +obj, | +
+ | + | const char * | +new_value | +
+ | ) | ++ |
Set the string value of a json_object with zero terminated strings equivalent to json_object_set_string_len (obj, new_value, strlen(new_value))
+JSON_EXPORT int json_object_set_string_len | +( | +json_object * | +obj, | +
+ | + | const char * | +new_value, | +
+ | + | int | +len | +
+ | ) | ++ |
Set the string value of a json_object str
+The type of obj is checked to be a json_type_string and 0 is returned if it is not without any further actions. If type of obj is json_type_string the object value is changed to new_value
+obj | the json_object instance |
new_value | the value to be set; Since string length is given in len this need not be zero terminated |
len | the length of new_value |
JSON_EXPORT int json_object_set_uint64 | +( | +struct json_object * | +obj, | +
+ | + | uint64_t | +new_value | +
+ | ) | ++ |
Set the uint64_t value of a json_object
+The type of obj is checked to be a json_type_uint and 0 is returned if it is not without any further actions. If type of obj is json_type_uint the object value is changed to new_value
+obj | the json_object instance |
new_value | the value to be set |
JSON_EXPORT void json_object_set_userdata | +( | +json_object * | +jso, | +
+ | + | void * | +userdata, | +
+ | + | json_object_delete_fn * | +user_delete | +
+ | ) | ++ |
Set an opaque userdata value for an object
+The userdata can be retrieved using json_object_get_userdata().
+If custom userdata is already set on this object, any existing user_delete function is called before the new one is set.
+The user_delete parameter is optional and may be passed as NULL, even if the userdata parameter is non-NULL. It will be called just before the json_object is deleted, after it's reference count goes to zero (see json_object_put()). If this is not provided, it is up to the caller to free the userdata at an appropriate time. (i.e. after the json_object is deleted)
+Note: Objects created by parsing strings may have custom serializers set which expect the userdata to contain specific data (due to use of json_object_new_double_s()). In this case, json_object_set_serialiser() with NULL as to_string_func should be used instead to set the userdata and reset the serializer to its default value.
+jso | the object to set the userdata for |
userdata | an optional opaque cookie |
user_delete | an optional function from freeing userdata |
JSON_EXPORT const char* json_object_to_json_string | +( | +struct json_object * | +obj | ) | ++ |
Stringify object to json format. Equivalent to json_object_to_json_string_ext(obj, JSON_C_TO_STRING_SPACED) The pointer you get is an internal of your json object. You don't have to free it, later use of json_object_put() should be sufficient. If you can not ensure there's no concurrent access to *obj use strdup().
+obj | the json_object instance |
JSON_EXPORT const char* json_object_to_json_string_ext | +( | +struct json_object * | +obj, | +
+ | + | int | +flags | +
+ | ) | ++ |
Stringify object to json format
+obj | the json_object instance |
flags | formatting options, see JSON_C_TO_STRING_PRETTY and other constants |
JSON_EXPORT const char* json_object_to_json_string_length | +( | +struct json_object * | +obj, | +
+ | + | int | +flags, | +
+ | + | size_t * | +length | +
+ | ) | ++ |
Stringify object to json format
+obj | the json_object instance |
flags | formatting options, see JSON_C_TO_STRING_PRETTY and other constants |
length | a pointer where, if not NULL, the length (without null) is stored |
JSON_EXPORT json_c_shallow_copy_fn json_c_shallow_copy_default | +
The default shallow copy implementation for use with json_object_deep_copy(). This simply calls the appropriate json_object_new_<type>() function and copies over the serializer function (_to_json_string internal field of the json_object structure) but not any _userdata or _user_delete values.
+If you're writing a custom shallow_copy function, perhaps because you're using your own custom serializer, you can call this first to create the new object before customizing it with json_object_set_serializer().
+JSON_EXPORT json_object_delete_fn json_object_free_userdata | +
Simply call free on the userdata pointer. Can be used with json_object_set_serializer().
+jso | unused |
userdata | the pointer that is passed to free(). |
JSON_EXPORT json_object_to_json_string_fn json_object_userdata_to_json_string | +
Copy the jso->_userdata string over to pb as-is. Can be used with json_object_set_serializer().
+jso | The object whose _userdata is used. |
pb | The destination buffer. |
level | Ignored. |
flags | Ignored. |
+ json-c
+ 0.16
+
+ |
+
An API for iterating over json_type_object objects, styled to be familiar to C++ programmers. Unlike json_object_object_foreach() and json_object_object_foreachC(), this avoids the need to expose json-c internals like lh_entry. +More...
++Data Structures | |
struct | json_object_iterator |
+Functions | |
JSON_EXPORT struct +json_object_iterator | json_object_iter_init_default (void) |
JSON_EXPORT struct +json_object_iterator | json_object_iter_begin (struct json_object *obj) |
JSON_EXPORT struct +json_object_iterator | json_object_iter_end (const struct json_object *obj) |
JSON_EXPORT void | json_object_iter_next (struct json_object_iterator *iter) |
JSON_EXPORT const char * | json_object_iter_peek_name (const struct json_object_iterator *iter) |
JSON_EXPORT struct json_object * | json_object_iter_peek_value (const struct json_object_iterator *iter) |
JSON_EXPORT json_bool | json_object_iter_equal (const struct json_object_iterator *iter1, const struct json_object_iterator *iter2) |
An API for iterating over json_type_object objects, styled to be familiar to C++ programmers. Unlike json_object_object_foreach() and json_object_object_foreachC(), this avoids the need to expose json-c internals like lh_entry.
+Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P.
+This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See COPYING for details.
+API attributes:
+
+
|
+ +read | +
Retrieves an iterator to the first pair of the JSON Object.
+obj | JSON Object instance (MUST be of type json_object) |
+
|
+ +read | +
Retrieves the iterator that represents the position beyond the last pair of the given JSON Object instance.
+obj | JSON Object instance (MUST be of type json_object) |
JSON_EXPORT json_bool json_object_iter_equal | +( | +const struct json_object_iterator * | +iter1, | +
+ | + | const struct json_object_iterator * | +iter2 | +
+ | ) | ++ |
Tests two iterators for equality. Typically used to test for end of iteration by comparing an iterator to the corresponding "end" iterator (that was derived from the same JSON Object instance).
+iter1 | Pointer to first valid, non-NULL iterator |
iter2 | POinter to second valid, non-NULL iterator |
+
|
+ +read | +
Initializes an iterator structure to a "default" value that is convenient for initializing an iterator variable to a default state (e.g., initialization list in a class' constructor).
+JSON_EXPORT void json_object_iter_next | +( | +struct json_object_iterator * | +iter | ) | ++ |
Returns an iterator to the next pair, if any
+iter | [IN/OUT] Pointer to iterator that references a name/value pair; MUST be a valid, non-end iterator. WARNING: bad things will happen if invalid or "end" iterator is passed. Upon return will contain the reference to the next pair if there is one; if there are no more pairs, will contain the "end" iterator value, which may be compared against the return value of json_object_iter_end() for the same JSON Object instance. |
JSON_EXPORT const char* json_object_iter_peek_name | +( | +const struct json_object_iterator * | +iter | ) | ++ |
Returns a const pointer to the name of the pair referenced by the given iterator.
+iter | pointer to iterator that references a name/value pair; MUST be a valid, non-end iterator. |
+
|
+ +read | +
Returns a pointer to the json-c instance representing the value of the referenced name/value pair, without altering the instance's reference count.
+iter | pointer to iterator that references a name/value pair; MUST be a valid, non-end iterator. |
+ json-c
+ 0.16
+
+ |
+
JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree. +More...
++Functions | |
JSON_EXPORT int | json_pointer_get (struct json_object *obj, const char *path, struct json_object **res) |
JSON_EXPORT int | json_pointer_getf (struct json_object *obj, struct json_object **res, const char *path_fmt,...) |
JSON_EXPORT int | json_pointer_set (struct json_object **obj, const char *path, struct json_object *value) |
JSON_EXPORT int | json_pointer_setf (struct json_object **obj, struct json_object *value, const char *path_fmt,...) |
JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree.
+JSON_EXPORT int json_pointer_get | +( | +struct json_object * | +obj, | +
+ | + | const char * | +path, | +
+ | + | struct json_object ** | +res | +
+ | ) | ++ |
Retrieves a JSON sub-object from inside another JSON object using the JSON pointer notation as defined in RFC 6901 https://tools.ietf.org/html/rfc6901
+The returned JSON sub-object is equivalent to parsing manually the 'obj' JSON tree ; i.e. it's not a new object that is created, but rather a pointer inside the JSON tree.
+Internally, this is equivalent to doing a series of 'json_object_object_get()' and 'json_object_array_get_idx()' along the given 'path'.
+Note that the 'path' string supports 'printf()' type arguments, so, whatever is added after the 'res' param will be treated as an argument for 'path' Example: json_pointer_get(obj, "/foo/%d/%s", &res, 0, bar) This means, that you need to escape '' with '%' (just like in printf())
+obj | the json_object instance/tree from where to retrieve sub-objects |
path | a (RFC6901) string notation for the sub-object to retrieve |
res | a pointer that stores a reference to the json_object associated with the given path |
JSON_EXPORT int json_pointer_getf | +( | +struct json_object * | +obj, | +
+ | + | struct json_object ** | +res, | +
+ | + | const char * | +path_fmt, | +
+ | + | + | ... | +
+ | ) | ++ |
This is a variant of 'json_pointer_get()' that supports printf() style arguments.
+Example: json_pointer_getf(obj, res, "/foo/%d/%s", 0, bak) This also means that you need to escape '' with '%' (just like in printf())
+Please take into consideration all recommended 'printf()' format security aspects when using this function.
+obj | the json_object instance/tree to which to add a sub-object |
res | a pointer that stores a reference to the json_object associated with the given path |
path_fmt | a printf() style format for the path |
JSON_EXPORT int json_pointer_set | +( | +struct json_object ** | +obj, | +
+ | + | const char * | +path, | +
+ | + | struct json_object * | +value | +
+ | ) | ++ |
Sets JSON object 'value' in the 'obj' tree at the location specified by the 'path'. 'path' is JSON pointer notation as defined in RFC 6901 https://tools.ietf.org/html/rfc6901
+Note that 'obj' is a double pointer, mostly for the "" (empty string) case, where the entire JSON object would be replaced by 'value'. In the case of the "" path, the object at '*obj' will have it's refcount decremented with 'json_object_put()' and the 'value' object will be assigned to it.
+For other cases (JSON sub-objects) ownership of 'value' will be transferred into '*obj' via 'json_object_object_add()' & 'json_object_array_put_idx()', so the only time the refcount should be decremented for 'value' is when the return value of 'json_pointer_set()' is negative (meaning the 'value' object did not get set into '*obj').
+That also implies that 'json_pointer_set()' does not do any refcount incrementing. (Just that single decrement that was mentioned above).
+Note that the 'path' string supports 'printf()' type arguments, so, whatever is added after the 'value' param will be treated as an argument for 'path' Example: json_pointer_set(obj, "/foo/%d/%s", value, 0, bak) This means, that you need to escape '' with '%' (just like in printf())
+obj | the json_object instance/tree to which to add a sub-object |
path | a (RFC6901) string notation for the sub-object to set in the tree |
value | object to set at path |
JSON_EXPORT int json_pointer_setf | +( | +struct json_object ** | +obj, | +
+ | + | struct json_object * | +value, | +
+ | + | const char * | +path_fmt, | +
+ | + | + | ... | +
+ | ) | ++ |
This is a variant of 'json_pointer_set()' that supports printf() style arguments.
+Example: json_pointer_setf(obj, value, "/foo/%d/%s", 0, bak) This also means that you need to escape '' with '%' (just like in printf())
+Please take into consideration all recommended 'printf()' format security aspects when using this function.
+obj | the json_object instance/tree to which to add a sub-object |
value | object to set at path |
path_fmt | a printf() style format for the path |
+ json-c
+ 0.16
+
+ |
+
Methods to parse an input string into a tree of json_object objects. +More...
++Data Structures | |
struct | json_tokener_srec |
struct | json_tokener |
+Macros | |
#define | JSON_TOKENER_DEFAULT_DEPTH 32 |
#define | JSON_TOKENER_STRICT 0x01 |
#define | JSON_TOKENER_ALLOW_TRAILING_CHARS 0x02 |
#define | JSON_TOKENER_VALIDATE_UTF8 0x10 |
+Typedefs | |
typedef struct json_tokener | json_tokener |
+Functions | |
JSON_EXPORT size_t | json_tokener_get_parse_end (struct json_tokener *tok) |
JSON_EXPORT const char * | json_tokener_error_desc (enum json_tokener_error jerr) |
JSON_EXPORT enum json_tokener_error | json_tokener_get_error (struct json_tokener *tok) |
JSON_EXPORT struct json_tokener * | json_tokener_new (void) |
JSON_EXPORT struct json_tokener * | json_tokener_new_ex (int depth) |
JSON_EXPORT void | json_tokener_free (struct json_tokener *tok) |
JSON_EXPORT void | json_tokener_reset (struct json_tokener *tok) |
JSON_EXPORT struct json_object * | json_tokener_parse (const char *str) |
JSON_EXPORT struct json_object * | json_tokener_parse_verbose (const char *str, enum json_tokener_error *error) |
JSON_EXPORT void | json_tokener_set_flags (struct json_tokener *tok, int flags) |
JSON_EXPORT struct json_object * | json_tokener_parse_ex (struct json_tokener *tok, const char *str, int len) |
Methods to parse an input string into a tree of json_object objects.
+#define JSON_TOKENER_ALLOW_TRAILING_CHARS 0x02 | +
Use with JSON_TOKENER_STRICT to allow trailing characters after the first parsed object.
+#define JSON_TOKENER_DEFAULT_DEPTH 32 | +
#define JSON_TOKENER_STRICT 0x01 | +
Be strict when parsing JSON input. Use caution with this flag as what is considered valid may become more restrictive from one release to the next, causing your code to fail on previously working input.
+Note that setting this will also effectively disable parsing of multiple json objects in a single character stream (e.g. {"foo":123}{"bar":234}); if you want to allow that also set JSON_TOKENER_ALLOW_TRAILING_CHARS
+This flag is not set by default.
+#define JSON_TOKENER_VALIDATE_UTF8 0x10 | +
Cause json_tokener_parse_ex() to validate that input is UTF8. If this flag is specified and validation fails, then json_tokener_get_error(tok) will return json_tokener_error_parse_utf8_string
+This flag is not set by default.
+typedef struct json_tokener json_tokener | +
enum json_tokener_error | +
enum json_tokener_state | +
JSON_EXPORT const char* json_tokener_error_desc | +( | +enum json_tokener_error | +jerr | ) | ++ |
Given an error previously returned by json_tokener_get_error(), return a human readable description of the error.
+JSON_EXPORT void json_tokener_free | +( | +struct json_tokener * | +tok | ) | ++ |
Free a json_tokener previously allocated with json_tokener_new().
+ +JSON_EXPORT enum json_tokener_error json_tokener_get_error | +( | +struct json_tokener * | +tok | ) | ++ |
Retrieve the error caused by the last call to json_tokener_parse_ex(), or json_tokener_success if there is no error.
+When parsing a JSON string in pieces, if the tokener is in the middle of parsing this will return json_tokener_continue.
+JSON_EXPORT size_t json_tokener_get_parse_end | +( | +struct json_tokener * | +tok | ) | ++ |
Return the offset of the byte after the last byte parsed relative to the start of the most recent string passed in to json_tokener_parse_ex(). i.e. this is where parsing would start again if the input contains another JSON object after the currently parsed one.
+Note that when multiple parse calls are issued, this is not the total number of characters parsed.
+In the past this would have been accessed as tok->char_offset.
+See json_tokener_parse_ex() for an example of how to use this.
+ +
+
|
+ +read | +
Allocate a new json_tokener. When done using that to parse objects, free it with json_tokener_free(). See json_tokener_parse_ex() for usage details.
+ +
+
|
+ +read | +
Allocate a new json_tokener with a custom max nesting depth.
+
+
|
+ +read | +
Parse a json_object out of the string str
.
If you need more control over how the parsing occurs, see json_tokener_parse_ex().
+ +
+
|
+ +read | +
Parse a string and return a non-NULL json_object if a valid JSON value is found. The string does not need to be a JSON object or array; it can also be a string, number or boolean value.
+A partial JSON string can be parsed. If the parsing is incomplete, NULL will be returned and json_tokener_get_error() will return json_tokener_continue. json_tokener_parse_ex() can then be called with additional bytes in str to continue the parsing.
+If json_tokener_parse_ex() returns NULL and the error is anything other than json_tokener_continue, a fatal error has occurred and parsing must be halted. Then, the tok object must not be reused until json_tokener_reset() is called.
+When a valid JSON value is parsed, a non-NULL json_object will be returned, with a reference count of one which belongs to the caller. Also, json_tokener_get_error() will return json_tokener_success. Be sure to check the type with json_object_is_type() or json_object_get_type() before using the object.
+Trailing characters after the parsed value do not automatically cause an error. It is up to the caller to decide whether to treat this as an error or to handle the additional characters, perhaps by parsing another json value starting from that point.
+If the caller knows that they are at the end of their input, the length passed MUST include the final '\0' character, so values with no inherent end (i.e. numbers) can be properly parsed, rather than just returning json_tokener_continue.
+Extra characters can be detected by comparing the value returned by json_tokener_get_parse_end() against the length of the last len parameter passed in.
+The tokener does not maintain an internal buffer so the caller is responsible for a subsequent call to json_tokener_parse_ex with an appropriate str parameter starting with the extra characters.
+This interface is presently not 64-bit clean due to the int len argument so the function limits the maximum string size to INT32_MAX (2GB). If the function is called with len == -1 then strlen is called to check the string length is less than INT32_MAX (2GB)
+Example:
+tok | a json_tokener previously allocated with json_tokener_new() |
str | an string with any valid JSON expression, or portion of. This does not need to be null terminated. |
len | the length of str |
+
|
+ +read | +
Parser a json_object out of the string str
, but if it fails return the error in *error
.
JSON_EXPORT void json_tokener_reset | +( | +struct json_tokener * | +tok | ) | ++ |
Reset the state of a json_tokener, to prepare to parse a brand new JSON object.
+ +JSON_EXPORT void json_tokener_set_flags | +( | +struct json_tokener * | +tok, | +
+ | + | int | +flags | +
+ | ) | ++ |
Set flags that control how parsing will be done.
+ +
+ json-c
+ 0.16
+
+ |
+
Basic types used in a few places in json-c, but you should include "json_object.h" instead. +More...
++Data Structures | |
struct | json_object_iter |
+Macros | |
#define | JSON_EXPORT extern |
+Typedefs | |
typedef struct json_object_iter | json_object_iter |
typedef int | json_bool |
typedef struct json_object | json_object |
The core type for all type of JSON objects handled by json-c. | |
typedef void( | json_object_delete_fn )(struct json_object *jso, void *userdata) |
typedef int( | json_object_to_json_string_fn )(struct json_object *jso, struct printbuf *pb, int level, int flags) |
typedef enum json_type | json_type |
+Enumerations | |
enum | json_type { + json_type_null, +json_type_boolean, +json_type_double, +json_type_int, + + json_type_object, +json_type_array, +json_type_string + + } |
Basic types used in a few places in json-c, but you should include "json_object.h" instead.
+#define JSON_EXPORT extern | +
typedef int json_bool | +
typedef struct json_object json_object | +
The core type for all type of JSON objects handled by json-c.
+ +typedef void( json_object_delete_fn)(struct json_object *jso, void *userdata) | +
Type of custom user delete functions. See json_object_set_serializer.
+ +typedef struct json_object_iter json_object_iter | +
typedef int( json_object_to_json_string_fn)(struct json_object *jso, struct printbuf *pb, int level, int flags) | +
Type of a custom serialization function. See json_object_set_serializer.
+ +enum json_type | +
+ json-c
+ 0.16
+
+ |
+
Miscllaneous utility functions and macros. +More...
++Macros | |
#define | json_min(a, b) ((a) < (b) ? (a) : (b)) |
#define | json_max(a, b) ((a) > (b) ? (a) : (b)) |
#define | JSON_FILE_BUF_SIZE 4096 |
+Functions | |
JSON_EXPORT struct json_object * | json_object_from_file (const char *filename) |
JSON_EXPORT struct json_object * | json_object_from_fd_ex (int fd, int depth) |
JSON_EXPORT struct json_object * | json_object_from_fd (int fd) |
JSON_EXPORT int | json_object_to_file (const char *filename, struct json_object *obj) |
JSON_EXPORT int | json_object_to_file_ext (const char *filename, struct json_object *obj, int flags) |
JSON_EXPORT int | json_object_to_fd (int fd, struct json_object *obj, int flags) |
JSON_EXPORT const char * | json_util_get_last_err (void) |
JSON_EXPORT int | json_parse_int64 (const char *buf, int64_t *retval) |
JSON_EXPORT int | json_parse_uint64 (const char *buf, uint64_t *retval) |
JSON_EXPORT int | json_parse_double (const char *buf, double *retval) |
JSON_EXPORT const char * | json_type_to_name (enum json_type o_type) |
Miscllaneous utility functions and macros.
+#define JSON_FILE_BUF_SIZE 4096 | +
#define json_max | +( | ++ | a, | +
+ | + | + | b | +
+ | ) | +((a) > (b) ? (a) : (b)) | +
#define json_min | +( | ++ | a, | +
+ | + | + | b | +
+ | ) | +((a) < (b) ? (a) : (b)) | +
+
|
+ +read | +
Create a JSON object from an already opened file descriptor, using the default maximum object depth. (JSON_TOKENER_DEFAULT_DEPTH)
+See json_object_from_fd_ex() for details.
+ +
+
|
+ +read | +
Create a JSON object from already opened file descriptor.
+This function can be helpful, when you opened the file already, e.g. when you have a temp file. Note, that the fd must be readable at the actual position, i.e. use lseek(fd, 0, SEEK_SET) before.
+The depth argument specifies the maximum object depth to pass to json_tokener_new_ex(). When depth == -1, JSON_TOKENER_DEFAULT_DEPTH is used instead.
+Returns NULL on failure. See json_util_get_last_err() for details.
+ +
+
|
+ +read | +
Read the full contents of the given file, then convert it to a json_object using json_tokener_parse().
+Returns NULL on failure. See json_util_get_last_err() for details.
+ +JSON_EXPORT int json_object_to_fd | +( | +int | +fd, | +
+ | + | struct json_object * | +obj, | +
+ | + | int | +flags | +
+ | ) | ++ |
Convert the json_object to a string and write it to the file descriptor. Handles partial writes and will keep writing until done, or an error occurs.
+fd | an open, writable file descriptor to write to |
obj | the object to serializer and write |
flags | flags to pass to json_object_to_json_string_ext() |
JSON_EXPORT int json_object_to_file | +( | +const char * | +filename, | +
+ | + | struct json_object * | +obj | +
+ | ) | ++ |
Equivalent to: json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN);
+Returns -1 if something fails. See json_util_get_last_err() for details.
+ +JSON_EXPORT int json_object_to_file_ext | +( | +const char * | +filename, | +
+ | + | struct json_object * | +obj, | +
+ | + | int | +flags | +
+ | ) | ++ |
Open and truncate the given file, creating it if necessary, then convert the json_object to a string and write it to the file.
+Returns -1 if something fails. See json_util_get_last_err() for details.
+ +JSON_EXPORT int json_parse_double | +( | +const char * | +buf, | +
+ | + | double * | +retval | +
+ | ) | ++ |
JSON_EXPORT int json_parse_int64 | +( | +const char * | +buf, | +
+ | + | int64_t * | +retval | +
+ | ) | ++ |
JSON_EXPORT int json_parse_uint64 | +( | +const char * | +buf, | +
+ | + | uint64_t * | +retval | +
+ | ) | ++ |
JSON_EXPORT const char* json_type_to_name | +( | +enum json_type | +o_type | ) | ++ |
Return a string describing the type of the object. e.g. "int", or "object", etc...
+ +JSON_EXPORT const char* json_util_get_last_err | +( | +void | +) | ++ |
Return the last error from various json-c functions, including: json_object_to_file{,ext}, json_object_to_fd() or json_object_from{file,fd}, or NULL if there is none.
+ +
+ json-c
+ 0.16
+
+ |
+
Methods for walking a tree of objects. +More...
++Macros | |
#define | JSON_C_VISIT_SECOND 0x02 |
#define | JSON_C_VISIT_RETURN_CONTINUE 0 |
#define | JSON_C_VISIT_RETURN_SKIP 7547 |
#define | JSON_C_VISIT_RETURN_POP 767 |
#define | JSON_C_VISIT_RETURN_STOP 7867 |
#define | JSON_C_VISIT_RETURN_ERROR -1 |
+Typedefs | |
typedef int( | json_c_visit_userfunc )(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, size_t *jso_index, void *userarg) |
+Functions | |
JSON_EXPORT int | json_c_visit (json_object *jso, int future_flags, json_c_visit_userfunc *userfunc, void *userarg) |
Methods for walking a tree of objects.
+#define JSON_C_VISIT_RETURN_CONTINUE 0 | +
This json_c_visit_userfunc return value indicates that iteration should proceed normally.
+ +#define JSON_C_VISIT_RETURN_ERROR -1 | +
This json_c_visit_userfunc return value indicates that iteration should stop immediately, and cause json_c_visit to return an error.
+ +#define JSON_C_VISIT_RETURN_POP 767 | +
This json_c_visit_userfunc return value indicates that iteration of the fields/elements of the containing object should stop and continue "popped up" a level of the object hierarchy. For example, returning this when handling arg will result in arg3 and any other fields being skipped. The next call to userfunc will be the JSON_C_VISIT_SECOND call on "foo", followed by a userfunc call on "bar".
++{ + "foo": { + "arg1": 1, + "arg2": 2, + "arg3": 3, + ... + }, + "bar": { + ... + } +} ++
#define JSON_C_VISIT_RETURN_SKIP 7547 | +
This json_c_visit_userfunc return value indicates that iteration over the members of the current object should be skipped. If the current object isn't a container (array or object), this is no different than JSON_C_VISIT_RETURN_CONTINUE.
+ +#define JSON_C_VISIT_RETURN_STOP 7867 | +
This json_c_visit_userfunc return value indicates that iteration should stop immediately, and cause json_c_visit to return success.
+ +#define JSON_C_VISIT_SECOND 0x02 | +
Passed to json_c_visit_userfunc as one of the flags values to indicate that this is the second time a container (array or object) is being called, after all of it's members have been iterated over.
+ +typedef int( json_c_visit_userfunc)(json_object *jso, int flags, json_object *parent_jso, const char *jso_key, size_t *jso_index, void *userarg) | +
JSON_EXPORT int json_c_visit | +( | +json_object * | +jso, | +
+ | + | int | +future_flags, | +
+ | + | json_c_visit_userfunc * | +userfunc, | +
+ | + | void * | +userarg | +
+ | ) | ++ |
Visit each object in the JSON hierarchy starting at jso. For each object, userfunc is called, passing the object and userarg. If the object has a parent (i.e. anything other than jso itself) its parent will be passed as parent_jso, and either jso_key or jso_index will be set, depending on whether the parent is an object or an array.
+Nodes will be visited depth first, but containers (arrays and objects) will be visited twice, the second time with JSON_C_VISIT_SECOND set in flags.
+userfunc must return one of the defined return values, to indicate whether and how to continue visiting nodes, or one of various ways to stop.
+Returns 0 if nodes were visited successfully, even if some were intentionally skipped due to what userfunc returned. Returns <0 if an error occurred during iteration, including if userfunc returned JSON_C_VISIT_RETURN_ERROR.
+ +
+ json-c
+ 0.16
+
+ |
+
Internal methods for working with json_type_object objects. Although this is exposed by the json_object_get_object() function and within the json_object_iter type, it is not recommended for direct use. +More...
++Data Structures | |
struct | lh_entry |
struct | lh_table |
+Macros | |
#define | LH_PRIME 0x9e370001UL |
#define | LH_LOAD_FACTOR 0.66 |
#define | LH_EMPTY (void *)-1 |
#define | LH_FREED (void *)-2 |
#define | JSON_C_STR_HASH_DFLT 0 |
#define | JSON_C_STR_HASH_PERLLIKE 1 |
#define | lh_foreach(table, entry) for (entry = lh_table_head(table); entry; entry = lh_entry_next(entry)) |
#define | lh_foreach_safe(table, entry, tmp) for (entry = lh_table_head(table); entry && ((tmp = lh_entry_next(entry)) || 1); entry = tmp) |
+Typedefs | |
typedef void( | lh_entry_free_fn )(struct lh_entry *e) |
typedef unsigned long( | lh_hash_fn )(const void *k) |
typedef int( | lh_equal_fn )(const void *k1, const void *k2) |
typedef struct lh_table | lh_table |
+Functions | |
int | json_global_set_string_hash (const int h) |
struct lh_table * | lh_table_new (int size, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, lh_equal_fn *equal_fn) |
struct lh_table * | lh_kchar_table_new (int size, lh_entry_free_fn *free_fn) |
struct lh_table * | lh_kptr_table_new (int size, lh_entry_free_fn *free_fn) |
void | lh_table_free (struct lh_table *t) |
int | lh_table_insert (struct lh_table *t, const void *k, const void *v) |
int | lh_table_insert_w_hash (struct lh_table *t, const void *k, const void *v, const unsigned long h, const unsigned opts) |
struct lh_entry * | lh_table_lookup_entry (struct lh_table *t, const void *k) |
struct lh_entry * | lh_table_lookup_entry_w_hash (struct lh_table *t, const void *k, const unsigned long h) |
json_bool | lh_table_lookup_ex (struct lh_table *t, const void *k, void **v) |
int | lh_table_delete_entry (struct lh_table *t, struct lh_entry *e) |
int | lh_table_delete (struct lh_table *t, const void *k) |
int | lh_table_length (struct lh_table *t) |
int | lh_table_resize (struct lh_table *t, int new_size) |
static struct lh_entry * | lh_table_head (const lh_table *t) |
static unsigned long | lh_get_hash (const struct lh_table *t, const void *k) |
static void * | lh_entry_k (const struct lh_entry *e) |
static int | lh_entry_k_is_constant (const struct lh_entry *e) |
static void * | lh_entry_v (const struct lh_entry *e) |
static void | lh_entry_set_val (struct lh_entry *e, void *newval) |
static struct lh_entry * | lh_entry_next (const struct lh_entry *e) |
static struct lh_entry * | lh_entry_prev (const struct lh_entry *e) |
Internal methods for working with json_type_object objects. Although this is exposed by the json_object_get_object() function and within the json_object_iter type, it is not recommended for direct use.
+#define JSON_C_STR_HASH_DFLT 0 | +
default string hash function
+ +#define JSON_C_STR_HASH_PERLLIKE 1 | +
perl-like string hash function
+ +#define LH_EMPTY (void *)-1 | +
sentinel pointer value for empty slots
+ +#define lh_foreach | +( | ++ | table, | +
+ | + | + | entry | +
+ | ) | +for (entry = lh_table_head(table); entry; entry = lh_entry_next(entry)) | +
Convenience list iterator.
+ +#define lh_foreach_safe | +( | ++ | table, | +
+ | + | + | entry, | +
+ | + | + | tmp | +
+ | ) | +for (entry = lh_table_head(table); entry && ((tmp = lh_entry_next(entry)) || 1); entry = tmp) | +
#define LH_FREED (void *)-2 | +
sentinel pointer value for freed slots
+ +#define LH_LOAD_FACTOR 0.66 | +
The fraction of filled hash buckets until an insert will cause the table to be resized. This can range from just above 0 up to 1.0.
+ +#define LH_PRIME 0x9e370001UL | +
golden prime used in hash functions
+ +typedef void( lh_entry_free_fn)(struct lh_entry *e) | +
callback function prototypes
+ +typedef int( lh_equal_fn)(const void *k1, const void *k2) | +
callback function prototypes
+ +typedef unsigned long( lh_hash_fn)(const void *k) | +
callback function prototypes
+ +int json_global_set_string_hash | +( | +const int | +h | ) | ++ |
This function sets the hash function to be used for strings. Must be one of the JSON_C_STR_HASH_* values.
+
+
|
+ +inlinestatic | +
Return a non-const version of lh_entry.k.
+lh_entry.k is const to indicate and help ensure that linkhash itself doesn't modify it, but callers are allowed to do what they want with it.
+References lh_entry::k.
+ +
+
|
+ +inlinestatic | +
Returns 1 if the key for the given entry is constant, and thus does not need to be freed when the lh_entry is freed.
+References lh_entry::k_is_constant.
+ +
+
|
+ +staticread | +
Return the next element, or NULL if there is no next element.
+References lh_entry::next.
+ +
+
|
+ +staticread | +
Return the previous element, or NULL if there is no previous element.
+References lh_entry::prev.
+ +
+
|
+ +inlinestatic | +
Change the value for an entry. The caller is responsible for freeing the previous value.
+ +References lh_entry::v.
+ +
+
|
+ +inlinestatic | +
Return a non-const version of lh_entry.v.
+v is const to indicate and help ensure that linkhash itself doesn't modify it, but callers are allowed to do what they want with it.
+ +References lh_entry::v.
+ +
+
|
+ +inlinestatic | +
Calculate the hash of a key for a given table.
+This is an extension to support functions that need to calculate the hash several times and allows them to do it just once and then pass in the hash to all utility functions. Depending on use case, this can be a considerable performance improvement.
+t | the table (used to obtain hash function) |
k | a pointer to the key to lookup |
References lh_table::hash_fn.
+ +
+
|
+ +read | +
Convenience function to create a new linkhash table with char keys.
+size | initial table size. |
free_fn | callback function used to free memory for entries. |
+
|
+ +read | +
Convenience function to create a new linkhash table with ptr keys.
+size | initial table size. |
free_fn | callback function used to free memory for entries. |
int lh_table_delete | +( | +struct lh_table * | +t, | +
+ | + | const void * | +k | +
+ | ) | ++ |
Delete a record from the table.
+If a callback free function is provided then it is called for the for the item being deleted.
+t | the table to delete from. |
k | a pointer to the key to delete. |
int lh_table_delete_entry | +( | +struct lh_table * | +t, | +
+ | + | struct lh_entry * | +e | +
+ | ) | ++ |
Delete a record from the table.
+If a callback free function is provided then it is called for the for the item being deleted.
+t | the table to delete from. |
e | a pointer to the entry to delete. |
void lh_table_free | +( | +struct lh_table * | +t | ) | ++ |
Free a linkhash table.
+If a lh_entry_free_fn callback free function was provided then it is called for all entries in the table.
+t | table to free. |
int lh_table_insert | +( | +struct lh_table * | +t, | +
+ | + | const void * | +k, | +
+ | + | const void * | +v | +
+ | ) | ++ |
Insert a record into the table.
+t | the table to insert into. |
k | a pointer to the key to insert. |
v | a pointer to the value to insert. |
0
is returned. On error, a negative value is returned. int lh_table_insert_w_hash | +( | +struct lh_table * | +t, | +
+ | + | const void * | +k, | +
+ | + | const void * | +v, | +
+ | + | const unsigned long | +h, | +
+ | + | const unsigned | +opts | +
+ | ) | ++ |
Insert a record into the table using a precalculated key hash.
+The hash h, which should be calculated with lh_get_hash() on k, is provided by the caller, to allow for optimization when multiple operations with the same key are known to be needed.
+t | the table to insert into. |
k | a pointer to the key to insert. |
v | a pointer to the value to insert. |
h | hash value of the key to insert |
opts | if set to JSON_C_OBJECT_ADD_CONSTANT_KEY, sets lh_entry.k_is_constant so t's free function knows to avoid freeing the key. |
int lh_table_length | +( | +struct lh_table * | +t | ) | ++ |
Return the number of entries in the table.
+ +
+
|
+ +read | +
Lookup a record in the table.
+t | the table to lookup |
k | a pointer to the key to lookup |
+
|
+ +read | +
Lookup a record in the table using a precalculated key hash.
+The hash h, which should be calculated with lh_get_hash() on k, is provided by the caller, to allow for optimization when multiple operations with the same key are known to be needed.
+t | the table to lookup |
k | a pointer to the key to lookup |
h | hash value of the key to lookup |
json_bool lh_table_lookup_ex | +( | +struct lh_table * | +t, | +
+ | + | const void * | +k, | +
+ | + | void ** | +v | +
+ | ) | ++ |
Lookup a record in the table.
+t | the table to lookup |
k | a pointer to the key to lookup |
v | a pointer to a where to store the found value (set to NULL if it doesn't exist). |
+
|
+ +read | +
Create a new linkhash table.
+size | initial table size. The table is automatically resized although this incurs a performance penalty. |
free_fn | callback function used to free memory for entries when lh_table_free or lh_table_delete is called. If NULL is provided, then memory for keys and values must be freed by the caller. |
hash_fn | function used to hash keys. 2 standard ones are defined: lh_ptr_hash and lh_char_hash for hashing pointer values and C strings respectively. |
equal_fn | comparison function to compare keys. 2 standard ones defined: lh_ptr_hash and lh_char_hash for comparing pointer values and C strings respectively. |
int lh_table_resize | +( | +struct lh_table * | +t, | +
+ | + | int | +new_size | +
+ | ) | ++ |
Resizes the specified table.
+t | Pointer to table to resize. |
new_size | New table size. Must be positive. |
0
is returned. On error, a negative value is returned.
+ json-c
+ 0.16
+
+ |
+
+ json-c
+ 0.16
+
+ |
+
This list was created with:
+curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=1" > issues1.out +curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=2" > issues2.out +curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=3" > issues3.out +jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),[Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md +#... manual editing ... +
Issues and Pull Requests closed for the 0.13 release (since commit f84d9c, the 0.12 branch point, 2014-04-10)
+size
variable \missing
is missing? \INSTALL
overrides an automake script. \This list was created with:
+curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=1" > issues1.out +curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=2" > issues2.out +curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=3" > issues3.out +jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),[Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md +#... manual editing ... +
Issues and Pull Requests closed for the 0.14 release (since commit d582d3a(2017-12-07) to a911439(2020-04-17))
+json_object *
in c++ \userdata
means?And what is the case we can use it? \This list was created with:
+curl "https://api.github.com/search/issues?q=repo%3Ajson-c%2Fjson-c+closed%3A>2020-04-18+created%3A<2020-07-23&sort=created&order=asc&per_page=100&page=1" > issues1.out +jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),* [Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md +#... manual editing ... +
Issues and Pull Requests closed for the 0.15 release (since commit 31ab57ca, the 0.14 branch point, 2020-04-19)
+-fPIC
compiler flag by default-fPIC
to link libjson-c.a with libsThis list was created with:
+PREV=2020-07-23 +NOW=2022-04-13 +curl "https://api.github.com/search/issues?q=repo%3Ajson-c%2Fjson-c+closed%3A>${PREV}+created%3A<${NOW}&sort=created&order=asc&per_page=100&page=1" > issues1.out +jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md +sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),* [Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md +cat issues.md >> issues_closed_for_0.16.md +
+ json-c
+ 0.16
+
+ |
+
![]() | |
![]() | |
![]() |
+ json-c
+ 0.16
+
+ |
+
Internal string buffer handling. Unless you're writing a json_object_to_json_string_fn implementation for use with json_object_set_serializer() direct use of this is not recommended. +More...
++Data Structures | |
struct | printbuf |
+Macros | |
#define | JSON_EXPORT extern |
#define | printbuf_memappend_fast(p, bufptr, bufsize) |
#define | printbuf_length(p) ((p)->bpos) |
#define | printbuf_strappend(pb, str) printbuf_memappend((pb), _printbuf_check_literal(str), sizeof(str) - 1) |
+Typedefs | |
typedef struct printbuf | printbuf |
+Functions | |
JSON_EXPORT struct printbuf * | printbuf_new (void) |
JSON_EXPORT int | printbuf_memappend (struct printbuf *p, const char *buf, int size) |
JSON_EXPORT int | printbuf_memset (struct printbuf *pb, int offset, int charvalue, int len) |
JSON_EXPORT int | sprintbuf (struct printbuf *p, const char *msg,...) |
JSON_EXPORT void | printbuf_reset (struct printbuf *p) |
JSON_EXPORT void | printbuf_free (struct printbuf *p) |
Internal string buffer handling. Unless you're writing a json_object_to_json_string_fn implementation for use with json_object_set_serializer() direct use of this is not recommended.
+#define JSON_EXPORT extern | +
#define printbuf_length | +( | ++ | p | ) | +((p)->bpos) | +
#define printbuf_memappend_fast | +( | ++ | p, | +
+ | + | + | bufptr, | +
+ | + | + | bufsize | +
+ | ) | ++ |
#define printbuf_strappend | +( | ++ | pb, | +
+ | + | + | str | +
+ | ) | +printbuf_memappend((pb), _printbuf_check_literal(str), sizeof(str) - 1) | +
This is an optimization wrapper around printbuf_memappend() that is useful for appending string literals. Since the size of string constants is known at compile time, using this macro can avoid a costly strlen() call. This is especially helpful when a constant string must be appended many times. If you got here because of a compilation error caused by passing something other than a string literal, use printbuf_memappend_fast() in conjunction with strlen().
+See also: printbuf_memappend_fast() printbuf_memappend() sprintbuf()
+ +JSON_EXPORT void printbuf_free | +( | +struct printbuf * | +p | ) | ++ |
JSON_EXPORT int printbuf_memappend | +( | +struct printbuf * | +p, | +
+ | + | const char * | +buf, | +
+ | + | int | +size | +
+ | ) | ++ |
JSON_EXPORT int printbuf_memset | +( | +struct printbuf * | +pb, | +
+ | + | int | +offset, | +
+ | + | int | +charvalue, | +
+ | + | int | +len | +
+ | ) | ++ |
Set len bytes of the buffer to charvalue, starting at offset offset. Similar to calling memset(x, charvalue, len);
+The memory allocated for the buffer is extended as necessary.
+If offset is -1, this starts at the end of the current data in the buffer.
+ +
+
|
+ +read | +
JSON_EXPORT void printbuf_reset | +( | +struct printbuf * | +p | ) | ++ |
JSON_EXPORT int sprintbuf | +( | +struct printbuf * | +p, | +
+ | + | const char * | +msg, | +
+ | + | + | ... | +
+ | ) | ++ |
Formatted print to printbuf.
+This function is the most expensive of the available functions for appending string data to a printbuf and should be used only where convenience is more important than speed. Avoid using this function in high performance code or tight loops; in these scenarios, consider using snprintf() with a static buffer in conjunction with one of the printbuf_*append() functions.
+See also: printbuf_memappend_fast() printbuf_memappend() printbuf_strappend()
+ +
+ json-c
+ 0.16
+
+ |
+
+Data Fields | |
void ** | array |
size_t | length |
size_t | size |
array_list_free_fn * | free_fn |
void** array_list::array | +
array_list_free_fn* array_list::free_fn | +
size_t array_list::length | +
size_t array_list::size | +
+ json-c
+ 0.16
+
+ |
+
+Data Fields | |
char * | key |
struct json_object * | val |
struct lh_entry * | entry |
A structure to use with json_object_object_foreachC() loops. Contains key, val and entry members.
+struct lh_entry* json_object_iter::entry | +
char* json_object_iter::key | +
struct json_object* json_object_iter::val | +
+ json-c
+ 0.16
+
+ |
+
+Data Fields | |
const void * | opaque_ |
The opaque iterator that references a name/value pair within a JSON Object instance or the "end" iterator value.
+const void* json_object_iterator::opaque_ | +
+ json-c
+ 0.16
+
+ |
+
+Data Fields | |
char * | str |
struct printbuf * | pb |
int | max_depth |
int | depth |
int | is_double |
int | st_pos |
int | char_offset |
enum json_tokener_error | err |
unsigned int | ucs_char |
unsigned int | high_surrogate |
char | quote_char |
struct json_tokener_srec * | stack |
int | flags |
Internal state of the json parser. Do not access any fields of this structure directly. Its definition is published due to historical limitations in the json tokener API, and will be changed to be an opaque type in the future.
+int json_tokener::char_offset | +
int json_tokener::depth | +
enum json_tokener_error json_tokener::err | +
int json_tokener::flags | +
unsigned int json_tokener::high_surrogate | +
int json_tokener::is_double | +
int json_tokener::max_depth | +
struct printbuf* json_tokener::pb | +
char json_tokener::quote_char | +
int json_tokener::st_pos | +
struct json_tokener_srec* json_tokener::stack | +
char* json_tokener::str | +
unsigned int json_tokener::ucs_char | +
+ json-c
+ 0.16
+
+ |
+
+Data Fields | |
enum json_tokener_state state | saved_state |
struct json_object * | obj |
struct json_object * | current |
char * | obj_field_name |
struct json_object* json_tokener_srec::current | +
struct json_object* json_tokener_srec::obj | +
char* json_tokener_srec::obj_field_name | +
enum json_tokener_state state json_tokener_srec::saved_state | +
+ json-c
+ 0.16
+
+ |
+
+Data Fields | |
const void * | k |
int | k_is_constant |
const void * | v |
struct lh_entry * | next |
struct lh_entry * | prev |
An entry in the hash table. Outside of linkhash.c, treat this as opaque.
+const void* lh_entry::k | +
The key.
+Referenced by lh_entry_k().
+ +int lh_entry::k_is_constant | +
A flag for users of linkhash to know whether or not they need to free k.
+Referenced by lh_entry_k_is_constant().
+ +struct lh_entry* lh_entry::next | +
The next entry.
+Referenced by lh_entry_next().
+ +struct lh_entry* lh_entry::prev | +
The previous entry.
+Referenced by lh_entry_prev().
+ +const void* lh_entry::v | +
The value.
+Referenced by lh_entry_set_val(), and lh_entry_v().
+ +
+ json-c
+ 0.16
+
+ |
+
+Data Fields | |
int | size |
int | count |
struct lh_entry * | head |
struct lh_entry * | tail |
struct lh_entry * | table |
lh_entry_free_fn * | free_fn |
lh_hash_fn * | hash_fn |
lh_equal_fn * | equal_fn |
The hash table structure. Outside of linkhash.c, treat this as opaque.
+int lh_table::count | +
Numbers of entries.
+lh_equal_fn* lh_table::equal_fn | +
lh_entry_free_fn* lh_table::free_fn | +
A pointer to the function responsible for freeing an entry.
+lh_hash_fn* lh_table::hash_fn | +
Referenced by lh_get_hash().
+ +struct lh_entry* lh_table::head | +
int lh_table::size | +
Size of our hash.
+struct lh_entry* lh_table::table | +
Internal storage of the actual table of entries.
+struct lh_entry* lh_table::tail | +
The last entry.
+
+ json-c
+ 0.16
+
+ |
+
+Data Fields | |
char * | buf |
int | bpos |
int | size |
int printbuf::bpos | +
char* printbuf::buf | +
int printbuf::size | +