utils / helpers

Header: json/util.h

Inline helpers to make things easier while process JSON. Most of uitl functions expects default value, so if it fails to convert string to a number or boolean then that default value will be returned.

Functions documentation

int32_t json_int32(const json_t * __restrict object, int32_t defaultValue)
creates number (int32) from string value
Parameters:
[in] object json object
[in] defaultValue default value if operation fails
Returns:
number
uint32_t json_uint32(const json_t * __restrict object, uint32_t defaultValue)
creates number (uint32) from string value
Parameters:
[in] object json object
[in] defaultValue default value if operation fails
Returns:
number
int64_t json_int64(const json_t * __restrict object, int64_t defaultValue)
creates number (int64) from string value
Parameters:
[in] object json object
[in] defaultValue default value if operation fails
Returns:
number
int64_t json_uint64(const json_t * __restrict object, uint64_t defaultValue)
creates number (uint64) from string value
Parameters:
[in] object json object
[in] defaultValue default value if operation fails
Returns:
number
float json_float(const json_t * __restrict object, float defaultValue)
creates number (float) from string value
Parameters:
[in] object json object
[in] defaultValue default value if operation fails
Returns:
number
double json_double(const json_t * __restrict object, double defaultValue)
creates number (double) from string value
Parameters:
[in] object json object
[in] defaultValue default value if operation fails
Returns:
number
int json_bool(const json_t * __restrict object, int defaultValue)
creates boolean from string value
it returns integer to separate default value from true or false
Parameters:
[in] object json object
[in] defaultValue default value if operation fails
Returns:
boolean values as integer: 1 true, 0 false, error: defaultValue
const char* json_string(const json_t * __restrict object)
return non-NULL terminated string value
you must use object->valSize to copy, compare … string
Parameters:
[in] object json object
Returns:
non-NULL terminated string value (pointer only)
char* json_string_dup(const json_t * __restrict object)
return non-NULL terminated string value
you must use object->valSize to copy, compare … string
Parameters:
[in] object json object
Returns:
NULL terminated duplicated string value
bool json_key_eq(const json_t * __restrict obj, const char * __restrict str)
compares json key with a string|
Parameters:
[in] obj json object
[in] str string to compare
Returns:
true if str is equals to json’s key