Microchip® Advanced Software Framework

winc1500/exosite_demo/iot/json.h File Reference

JSON parser.

Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.

#include <stdint.h>
#include <stdlib.h>

Data Structures

struct  json_obj
 JSON data structure. More...
 

Macros

#define JSON_MAX_NAME_SIZE   16
 Max size of token name. More...
 
#define JSON_MAX_TOKEN_SIZE   64
 Max token size of JSON element. More...
 

Enumerations

enum  json_type {
  JSON_TYPE_NULL = 0,
  JSON_TYPE_OBJECT,
  JSON_TYPE_STRING,
  JSON_TYPE_BOOLEAN,
  JSON_TYPE_INTEGER,
  JSON_TYPE_REAL,
  JSON_TYPE_ARRAY,
  JSON_TYPE_MAX,
  JSON_TYPE_NULL = 0,
  JSON_TYPE_OBJECT,
  JSON_TYPE_STRING,
  JSON_TYPE_BOOLEAN,
  JSON_TYPE_INTEGER,
  JSON_TYPE_REAL,
  JSON_TYPE_ARRAY,
  JSON_TYPE_MAX,
  JSON_TYPE_NULL = 0,
  JSON_TYPE_OBJECT,
  JSON_TYPE_STRING,
  JSON_TYPE_BOOLEAN,
  JSON_TYPE_INTEGER,
  JSON_TYPE_REAL,
  JSON_TYPE_ARRAY,
  JSON_TYPE_MAX
}
 JSON type. More...
 

Functions

int json_create (struct json_obj *obj, const char *data, int data_len)
 Create the JSON data from the string buffer. More...
 
int json_find (struct json_obj *obj, const char *name, struct json_obj *out)
 Find data from the JSON object. More...
 
int json_get_child (struct json_obj *obj, int index, struct json_obj *out)
 Get child data in the JSON object. More...
 
int json_get_child_count (struct json_obj *obj)
 Get child count in the JSON object. More...
 

#define JSON_MAX_NAME_SIZE   16

Max size of token name.

#define JSON_MAX_TOKEN_SIZE   64

Max token size of JSON element.

Token means that pair of key and value.

enum json_type

JSON type.

Enumerator
JSON_TYPE_NULL 
JSON_TYPE_OBJECT 
JSON_TYPE_STRING 
JSON_TYPE_BOOLEAN 
JSON_TYPE_INTEGER 
JSON_TYPE_REAL 
JSON_TYPE_ARRAY 
JSON_TYPE_MAX 
JSON_TYPE_NULL 
JSON_TYPE_OBJECT 
JSON_TYPE_STRING 
JSON_TYPE_BOOLEAN 
JSON_TYPE_INTEGER 
JSON_TYPE_REAL 
JSON_TYPE_ARRAY 
JSON_TYPE_MAX 
JSON_TYPE_NULL 
JSON_TYPE_OBJECT 
JSON_TYPE_STRING 
JSON_TYPE_BOOLEAN 
JSON_TYPE_INTEGER 
JSON_TYPE_REAL 
JSON_TYPE_ARRAY 
JSON_TYPE_MAX 

int json_create ( struct json_obj obj,
const char *  data,
int  data_len 
)

Create the JSON data from the string buffer.

Parameters
[out]objPointer of JSON token which will be stored json informations.
[in]dataJSON data represented as a string.
[in]data_lenJSON data length.
Returns
0 Success.
otherwise Failed to create.
int json_find ( struct json_obj obj,
const char *  name,
struct json_obj out 
)

Find data from the JSON object.

The input should be an object or array. This function supported colon separated search.

If JSON data is as follows {"obj1":{"data1":"value1","data2":"value2","obj2":{"data3":"value3"}}} You can be found value of data3 using the following name variable. "obj1:obj2:data3"

Parameters
[in]objPointer of the parent JSON data.
[in]nameThe name of the item you are looking for.
[in]outPointer of JSON token which will be stored child JSON informations.
Returns
0 Success.
otherwise Failed to create.
int json_get_child ( struct json_obj obj,
int  index,
struct json_obj out 
)

Get child data in the JSON object.

The input should be an object or array.

Parameters
[in]objPointer of the parent JSON data.
[in]indexIndex which is located in the parent object.
[in]outPointer of JSON token which will be stored child JSON informations.
Returns
0 Success.
otherwise Failed to create.
int json_get_child_count ( struct json_obj obj)

Get child count in the JSON object.

The input should be an object or array.

Parameters
[in]objPointer of the parent JSON data.
Returns
0 Success.
otherwise Failed to create.