MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages

Query JSON object hierarchy using key paths (obsolete) More...

Functions

int32_t json_object_path_get_int (struct json_object *src, char const *key_path)
 Get integer value for object at specified path. More...
 
int64_t json_object_path_get_int64 (struct json_object *src, char const *key_path)
 Get int64 value for object at specified path. More...
 
double json_object_path_get_double (struct json_object *src, char const *key_path)
 Get a double value for the object at specified path. More...
 
json_bool json_object_path_get_boolean (struct json_object *src, char const *key_path)
 Get boolean value for the object at specified path. More...
 
char const * json_object_path_get_string (struct json_object *src, char const *key_path)
 Get a string value for the object at specified path. More...
 
struct json_objectjson_object_path_get_array (struct json_object *src, char const *key_path)
 Get the array object at specified path. More...
 
struct json_objectjson_object_path_get_object (struct json_object *src, char const *key_path)
 Get the object at specified path. More...
 
struct json_objectjson_object_path_get_extarr (struct json_object *src, char const *key_path)
 Get the extarr object at specified path. More...
 
struct json_objectjson_object_path_get_any (struct json_object *src, char const *key_path)
 Get object of any type at specified path. More...
 

Detailed Description

Query JSON object hierarchy using key paths (obsolete)

These methods support querying values from a hierarchy of JSON objects using unix-style pathnames for sequences of keys. In addition, for those methods that are intended to return a primitive value (e.g. not an object), sane type casting (coercion) is performed if the requested type and matching object's type are different.

Due to the need to construct key path strings used in these calls, it is often more convenient to use the JsonGetXXX macros instead. See, for example, JsonGetInt().

Function Documentation

int32_t json_object_path_get_int ( struct json_object src,
char const *  key_path 
)

Get integer value for object at specified path.

Returns
If the object being queried does not exist, zero is returned. If the object being queried exists and is type
  • json_bool, JSON_C_TRUE returns 1 and JSON_C_FALSE returns 0.
  • number, the value of the number cast to an int type is returned.
  • string
    1. holding a number, the value after casting to int the result of strtod on the string is returned.
    2. holding anything else, the length of the string is returned.
  • an object, the size of the object is returned.

Definition at line 2103 of file json_object.c.

int64_t json_object_path_get_int64 ( struct json_object src,
char const *  key_path 
)

Get int64 value for object at specified path.

Same as json_object_path_get_int() except that an int64_t type value is returned.

Definition at line 2118 of file json_object.c.

double json_object_path_get_double ( struct json_object src,
char const *  key_path 
)

Get a double value for the object at specified path.

Returns
If the object being queried does not exist, 0.0 is returned. If the object being queried exists and is type
  • json_bool, JSON_C_TRUE returns 1.0 and JSON_C_FALSE returns 0.0.
  • a number, the result of casting the number to type double is returned
  • a string
    1. holding a number, the value returned from strtod() on the string is returned.
    2. holding anything else, the length of the string is returned.
  • an object, the size of the object is returned.

Definition at line 2140 of file json_object.c.

json_bool json_object_path_get_boolean ( struct json_object src,
char const *  key_path 
)

Get boolean value for the object at specified path.

Returns
If the object being queried does not exist, JSON_C_FALSE is returned. If the object being queried exists and its type is a
  • json_bool, its value is returned.
  • number, if the number's value is zero, JSON_C_FALSE is returned.
  • string, if the string is empty, JSON_C_FALSE is returned.
  • object, if the length of the object is zero, JSON_C_FALSE is returned.
  • In all other cases, a value of JSON_C_TRUE is returned.

Definition at line 2161 of file json_object.c.

char const* json_object_path_get_string ( struct json_object src,
char const *  key_path 
)

Get a string value for the object at specified path.

Other path get methods return a fixed size value whether they succeed or fail. Queries for non-existent or mis-matching types are for the most part harmless. Here, however, as long as the object identified by path exists, this method will return a variable length ascii string representation. Therefore, callers should beware of the need to exercise more caution in ensuring the queried strings are actually needed. Also, the resultant strings are cached internally in their respective objects. The caller may wish to free printbuf memory associated with the string. That memory is associated with the queried object. So, the caller must first obtain a handle (pointer) to the queried object.

1 char const *some_string = json_object_path_get_string(obj, "/foo/bar");
2 .
3 . do some work with the string
4 .
5 json_object *some_obj = json_object_path_get_object(obj, "/foo/bar");
6 json_object_free_printbuf(some_obj);
Returns
If the object being queried does not exist, the string "null" is returned. If the object being queried exists, the result of json_object_to_json_string_ext() is returned.

Definition at line 2198 of file json_object.c.

struct json_object* json_object_path_get_array ( struct json_object src,
char const *  key_path 
)

Get the array object at specified path.

Returns
If the object being queried is does not exist, (json_object *)0 is returned. If the object being queried is not an ordinary array, (json_object *)0 is returned. Otherwise, the json_object* for the array object is returned.

Definition at line 2215 of file json_object.c.

struct json_object* json_object_path_get_object ( struct json_object src,
char const *  key_path 
)

Get the object at specified path.

Returns
If the object being queried is does not exist, (json_object *)0 is returned. If the object being queried is not an ordinary object, (json_object *)0 is returned. Otherwise, the json_object* for the object is returned.

Definition at line 2232 of file json_object.c.

struct json_object* json_object_path_get_extarr ( struct json_object src,
char const *  key_path 
)

Get the extarr object at specified path.

Returns
If the object being queried is does not exist, (json_object *)0 is returned. If the object being queried is not an extarr object, (json_object *)0 is returned. Otherwise, the json_object* for the extarr object is returned.

Definition at line 2249 of file json_object.c.

struct json_object* json_object_path_get_any ( struct json_object src,
char const *  key_path 
)

Get object of any type at specified path.

Returns
If the object being queried is does not exist, (json_object *)0 is returned. Otherwise, the json_object* for the object is returned.

Definition at line 2265 of file json_object.c.