jkii
Data Fields
jkii_field_t Struct Reference

#include <jkii.h>

Data Fields

const char * name
 
const char * path
 
jkii_field_err_t result
 
jkii_field_type_t type
 
size_t start
 
size_t end
 
union {
   char *   string
 
   int   int_value
 
   long   long_value
 
   double   double_value
 
   jkii_boolean_t   boolean_value
 
field_copy
 
size_t field_copy_buff_size
 

Detailed Description

JSON parsed field data.

Input of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

Array of jkii_field_t is passed to jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

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

Field Documentation

◆ boolean_value

jkii_boolean_t jkii_field_t::boolean_value

This value is used if jkii_field_t::type is jkii_field_type_t::JKII_FIELD_TYPE_BOOLEAN.

◆ double_value

double jkii_field_t::double_value

This value is used if jkii_field_t::type is jkii_field_type_t::JKII_FIELD_TYPE_DOUBLE. If parsing target is overflowed, then this value is plus or minus HUGE_VAL. If parsing is underflowed, then this value is 0.

◆ end

size_t jkii_field_t::end

End point of this field in given buffer. Output of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

◆ field_copy

union { ... } jkii_field_t::field_copy

Buffer to copy field value. if NULL, no copy is generated. Using value is determined by value of jkii_field_t::type. If jkii_field_t::type is jkii_field_type_t::JKII_FIELD_TYPE_NULL, no copy is generated.

◆ field_copy_buff_size

size_t jkii_field_t::field_copy_buff_size

Length of field_copy::string. ignored if field_copy::string is null or jkii_field_t::type is not jkii_field_type_t::JKII_FIELD_TYPE_STRING, jkii_field_type_t::JKII_FIELD_TYPE_OBJECT and jkii_field_type_t::JKII_FIELD_TYPE_ARRAY.

◆ int_value

int jkii_field_t::int_value

This value is used if jkii_field_t::type is jkii_field_type_t::JKII_FIELD_TYPE_INTEGER. If parsing target is overflowed, then this value is INT_MAX. If parsing is underflowed, then this value is INT_MIN.

◆ long_value

long jkii_field_t::long_value

This value is used if jkii_field_t::type is jkii_field_type_t::JKII_FIELD_TYPE_LONG. If parsing target is overflowed, then this value is LONG_MAX. If parsing is underflowed, then this value is LONG_MIN.

◆ name

const char* jkii_field_t::name

Parsing target key name. Input of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

Addressing a top-level field in a json object.

◆ path

const char* jkii_field_t::path

Parsing target path. Input of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

This can point any field or element of array. BNF like notation of path is following:

path ::= '/' identifier subpath
subpath ::= '/' identifier subpath | ''
identifier ::= field | index
index ::= '[' 0 ']' | '[' [1-9][0-9]+ ']'
field ::= [char | escaped]+
char ::= any ascii characters expect '/', '[', ']' and '\'
escaped = "\\/" | "\\[" | "\\]" | "\\"

If you want to get first element of color array in following json example:

{
"light" : {
"color" : [ 0, 128, 255]
}
}
path ="/light/color/[0]";

In rare cases, like following:

{
"[]/\\" : "rare"
}

You can specify "[]/\\" as following:

path ="/\\[\\]\\/\\";

◆ result

jkii_field_err_t jkii_field_t::result

Field parse result. Output of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

◆ start

size_t jkii_field_t::start

Start point of this field in given buffer. Output of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

◆ string

char* jkii_field_t::string

This value is used if jkii_field_t::type is jkii_field_type_t::JKII_FIELD_TYPE_STRING, jkii_field_type_t::JKII_FIELD_TYPE_OBJECT or jkii_field_type_t::JKII_FIELD_TYPE_ARRAY.

◆ type

jkii_field_type_t jkii_field_t::type

Parsed target value type. Input and Output of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*). Inputted value is expected value type and outputted value is actual value type.

If type is set as jkii_field_type_t::JKII_FIELD_TYPE_ANY, then jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*) ignore type checking.

If actual type is not matched expected type:

  • jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*) set actual type.
  • if expected type is not jkii_field_type_t::JKII_FIELD_TYPE_ANY, then jkii_field_t::result becomes jkii_parse_err_t::JKII_FIELD_ERR_TYPE_MISMATCH.
  • if expected type is jkii_field_type_t::JKII_FIELD_TYPE_ANY, then jkii_field_t::result become jkii_parse_err_t::JKII_FIELD_ERR_OK.

The documentation for this struct was generated from the following file: