Types and Enums
jsmn_parse
parser
| Direction | Name | Type | Description |
|---|---|---|---|
| In | pos | UDINT | Current parsing position within the JSON string |
| Internal | toknext | UDINT | Keeps track of next token index |
| Internal | toksuper | UDINT | Keeps track of the token associated with the parent JSON object |
| In | callback | jsmn_callback | Callback data to be used (Optional) |
| Out | isValue | BOOL | Boolean set when the value of a JSON object is parsed |
| In | pcache | UDINT | Pointer to cache to be used (Optional) |
| Out | endPos | UDINT | End parsing position within the JSON string |
| Internal | cache | STRING[] | Size of JSMN_STRLEN_CACHE. Internal cache used for parsing if pcache is not specified. |
parser.callback (jsmn_callback)
| Name | Type | Description |
|---|---|---|
| pFunction | UDINT | Pointer to user defined callback function used to sort parsed data |
| pUserData | UDINT | Pointer to user defined data structure used to store parsed data |
jsmn_callback_data
| Name | Variable Type | Description |
|---|---|---|
| Name | STRING | Highest level variable name of currently parsed JSON Object |
| Type | json_token_type_enum | Token type (object, array, string, etc…), see json_token_type_enum for more info |
| Value | STRING | Parsed value of token as a string (“true”, “2”, etc…) |
| Levels | USINT | JSON hierarchy depth |
| Structure | STRING ARRAY | JSON hierarchy stored as an array |
| Size | UDINT | Size of current data structure. Currently 0 for primitive values and 1 for Members, Object, and Arrays |
| Advanced | jsmn_callback_advanced_data | Contains additional information not needed for most situations |
jsmn_callback_advanced_data
| Name | Variable Type | Description |
|---|---|---|
| pValue | UDINT | Pointer to start of value in original json string |
| ValueLen | UDINT | Length of value |
Tokens
jsmntok_t
| Name | Variable Type | Description |
|---|---|---|
| type | json_token_type_enum | Token type (object, array, string, etc…), see json_token_type_enum for more info |
| start | INT | Start position in JSON data string |
| end | INT | End position in JSON data string |
| size | INT | String length of token name |
| parent | INT | Token index of parent. For internal use |
| cached | BOOL | Token is contained in parser’s cache. For internal use |
json_token
Warning
This type has not use as all use cases are Deprecated. Use jsmntok_t instead! May be revived in future library versions.
Modified type similar to jsmntok_t to be used with JsonParse and associated functions.
| Name | Variable Type | Description |
|---|---|---|
| Type | json_token_type_enum | Token type (object, array, string, etc…), see json_token_type_enum for more info |
| Start | INT | Start position in JSON data string |
| End | INT | End position in JSON data string |
| Size | INT | String length of token name |
| parent | INT | Token index of parent ? For internal use |
| cached | BOOL | For internal use |
json_token_type_enum
| Value | Enum | Description |
|---|---|---|
| 0 | JSON_UNDEFINED | Type of undefined |
| 1 | JSMN_OBJECT | Type of Object |
| 2 | JSMN_ARRAY | Type of Array |
| 3 | JSMN_STRING | Type of String |
| 4 | JSMN_PRIMITIVE | Type of Primitive (number, boolean, etc…) |
Constants
| Name | Type | Value | Description |
|---|---|---|---|
| JSMN_MAX_TOKENS | USINT | 128 | Max number of tokens supported by JsonParse, JsonTokenEqual, and JSONGetValue |
| JSMN_MAI_STRUCT_LEVEL | USINT | 15 | Mai number of structures level displayed in jsmn_callback_data Structure[] member |
| JSMN_STRLEN_CALLBACK_DATA | UINT | 320 | Max string length of information provided in jsmn_callback_data |
| JSMN_STRLEN_CACHE | UINT | 1000 | Size of parser internal cache |
Errors
| Value | Enum | Description |
|---|---|---|
| -1 | JSMN_ERROR_NO_MEM | Not enough tokens were provided |
| -2 | JSMN_ERROR_INVAL | Invalid character inside JSON string |
| -3 | JSMN_ERROR_PART | The string is not a full JSON packet, more bytes expected |