Kii JSON
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Classes | Typedefs | Enumerations | Functions
kii_json.h File Reference

This is a file defining Kii JSON APIs. More...

#include <jsmn.h>

Go to the source code of this file.

Classes

struct  kii_json_resource_t
 
struct  kii_json_t
 
struct  kii_json_field_t
 

Typedefs

typedef jsmntok_t kii_json_token_t
 
typedef struct kii_json_resource_t kii_json_resource_t
 
typedef int(* KII_JSON_RESOURCE_CB )(kii_json_resource_t *resource, size_t required_size)
 
typedef struct kii_json_t kii_json_t
 
typedef enum kii_json_boolean_t kii_json_boolean_t
 
typedef enum
kii_json_parse_result_t 
kii_json_parse_result_t
 
typedef enum
kii_json_field_parse_result_t 
kii_json_field_parse_result_t
 
typedef enum kii_json_field_type_t kii_json_field_type_t
 
typedef struct kii_json_field_t kii_json_field_t
 

Enumerations

enum  kii_json_boolean_t { KII_JSON_FALSE, KII_JSON_TRUE }
 
enum  kii_json_parse_result_t {
  KII_JSON_PARSE_SUCCESS, KII_JSON_PARSE_PARTIAL_SUCCESS, KII_JSON_PARSE_ROOT_TYPE_ERROR, KII_JSON_PARSE_SHORTAGE_TOKENS,
  KII_JSON_PARSE_INVALID_INPUT
}
 
enum  kii_json_field_parse_result_t {
  KII_JSON_FIELD_PARSE_SUCCESS, KII_JSON_FIELD_PARSE_TYPE_UNMATCHED, KII_JSON_FIELD_PARSE_NOT_FOUND, KII_JSON_FIELD_PARSE_COPY_FAILED,
  KII_JSON_FIELD_PARSE_COPY_OVERFLOW, KII_JSON_FIELD_PARSE_COPY_UNDERFLOW
}
 
enum  kii_json_field_type_t {
  KII_JSON_FIELD_TYPE_ANY, KII_JSON_FIELD_TYPE_INTEGER, KII_JSON_FIELD_TYPE_LONG, KII_JSON_FIELD_TYPE_DOUBLE,
  KII_JSON_FIELD_TYPE_BOOLEAN, KII_JSON_FIELD_TYPE_NULL, KII_JSON_FIELD_TYPE_STRING, KII_JSON_FIELD_TYPE_OBJECT,
  KII_JSON_FIELD_TYPE_ARRAY
}
 

Functions

kii_json_parse_result_t kii_json_read_object (kii_json_t *kii_json, const char *json_string, size_t json_string_len, kii_json_field_t *fields)
 

Detailed Description

This is a file defining Kii JSON APIs.

Typedef Documentation

Boolean type

Field parsing result. Assigned to kii_json_field_t::result.

JSON parsed field data.

Input of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

Array of kii_json_field_t is passed to kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

End point of the array is specified by kii_json_field_t::name and kii_json_field_t::path. If both of kii_json_field_t::name and kii_json_field_t::path are NULL, kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*) consider that it is the end point of the passed array.

Type of parsed JSON field. This value is assigned to kii_json_field_t::type.

Return value of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*)

typedef int(* KII_JSON_RESOURCE_CB)(kii_json_resource_t *resource, size_t required_size)

Resource allocator for kii_json_resource_t.

When parsing target JSON string requires more tokens provided by kii_json_resource_t, This function is called. You need to resize kii_json_resource_t::tokens and set new size to kii_json_resource_t::tokens_num which is greater than or equal to required_size.

If you allocate new resource, Application may need to free old resource since the library never free the given resource.

Parameters
[in,out]resourcekii json resources used by KII JSON library.
[in]required_sizenewly required token size.
Returns
1: success to allocate resource, 0: fail to allocate resourceresize.

Resource used by KII JSON library. Fields of this struct determines max number of tokens inside json can be parsed.

typedef struct kii_json_t kii_json_t

object manages context of kii json apis. Do not share this object and fields inside this object among the thread/tasks. library won't sync the request if the multiple threads/tasks share the resource.

typedef jsmntok_t kii_json_token_t

JSON token data to parse JSON string.

Enumeration Type Documentation

Boolean type

Enumerator
KII_JSON_FALSE 
KII_JSON_TRUE 

Field parsing result. Assigned to kii_json_field_t::result.

Enumerator
KII_JSON_FIELD_PARSE_SUCCESS 

Field parsing is success.

KII_JSON_FIELD_PARSE_TYPE_UNMATCHED 

Type of field specified kii_json_field_t::type is unmathced.

KII_JSON_FIELD_PARSE_NOT_FOUND 

Field specified by kii_json_field_t::name is not found.

KII_JSON_FIELD_PARSE_COPY_FAILED 

Coping string to kii_json_field_t::field_copy::string is failed. kii_json_field_t::field_copy_buff_size may shorter than actual length.

KII_JSON_FIELD_PARSE_COPY_OVERFLOW 

Coping int, long or double value to kii_json_field_t::field_copy::int_value, kii_json_field_t::field_copy::long_value or kii_json_field_t::field_copy::double_value is failed. value is overflowed.

KII_JSON_FIELD_PARSE_COPY_UNDERFLOW 

Coping int, long or double value to kii_json_field_t::field_copy::int_value, kii_json_field_t::field_copy::long_value or kii_json_field_t::field_copy::double_value is failed. value is underflowed.

Type of parsed JSON field. This value is assigned to kii_json_field_t::type.

Enumerator
KII_JSON_FIELD_TYPE_ANY 

This value denotes any JSON types. If this value is set to kii_json_field_t::type, then kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*) ignore type checking.

KII_JSON_FIELD_TYPE_INTEGER 

This values denotes an signed interger value. Maximum is INT_MAX and Minimum is INT_MIN.

KII_JSON_FIELD_TYPE_LONG 

This values denotes an signed interger value. Maximum is LONG_MAX and Minimum is LONG_MIN.

KII_JSON_FIELD_TYPE_DOUBLE 

This value denotes an double value.

KII_JSON_FIELD_TYPE_BOOLEAN 

This value denotes kii_json_boolean_t value.

KII_JSON_FIELD_TYPE_NULL 

This value denotes denotes NULL value.

KII_JSON_FIELD_TYPE_STRING 

This value denotes JSON string.

KII_JSON_FIELD_TYPE_OBJECT 

This value denotes JSON object.

KII_JSON_FIELD_TYPE_ARRAY 

This value denotes JSON array.

Return value of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*)

Enumerator
KII_JSON_PARSE_SUCCESS 

JSON string is successfully parsed and all kii_json_field_t variables are successfully set. i.e., all kii_json_field_t type fields are KII_JSON_FIELD_PARSE_SUCCESS.

KII_JSON_PARSE_PARTIAL_SUCCESS 

JSON string is successfully parsed but some kii_json_field_t variables are failed. i.e., some kii_json_field_t type fields are not KII_JSON_FIELD_PARSE_SUCCESS.

KII_JSON_PARSE_ROOT_TYPE_ERROR 

JSON string is successfully parsed but type of root object type is unmatched to using function.

kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*) requires JSON object if JSON array is passed, then this error is returned.

KII_JSON_PARSE_SHORTAGE_TOKENS 

kii_json_t::tokens is not enough to parse JSON string.

KII_JSON_PARSE_INVALID_INPUT 

JSON string is failed to parse. Passed string is not JSON string.

Function Documentation

kii_json_parse_result_t kii_json_read_object ( kii_json_t kii_json,
const char *  json_string,
size_t  json_string_len,
kii_json_field_t fields 
)

parse JSON string as JSON object.

Parameters
[in]kiijson instance.
[in]pointerof JSON string.
[in]lengthof JSON string.
[in,out]fieldof kii JSON parser.
Returns
parse JSON result.