#include <stdio.h>
#include <string.h>
#include "cy_result.h"
#include "cy_json_parser.h"
char str_snippet[] = " { \"arr\":[1,2,3], \"bool\":true, \"url\": \"https://www.httpbin.org/get\", \"number\": 10000 , \"float\":3.14, \"NULL_VAL\":null}";
static cy_rslt_t parse_json_snippet_callback (
cy_JSON_object_t* json_object,
void *arg )
{
{
{
break;
}
{
printf(
"Found a number: %ld\n", (
unsigned long)json_object->
intval);
break;
}
{
printf(
"Found a float: %f\n",json_object->
floatval);
break;
}
{
printf(
"Found a boolean: %d\n",(
unsigned int)json_object->
boolval);
break;
}
{
break;
}
{
printf("Found an ARRAY");
break;
}
default:
{
break;
}
}
return 0;
}
int json_parser_snippet(void)
{
if (
cy_JSON_parser(str_snippet , strlen(str_snippet)) == CY_RSLT_SUCCESS)
{
printf("Successfully parsed the JSON input\n");
return 0;
}
else
{
printf("Failed to parse the JSON input\n");
return -1;
}
}
@ JSON_NULL_TYPE
JSON null object.
Definition: cy_json_parser.h:82
@ JSON_ARRAY_TYPE
JSON array datatype.
Definition: cy_json_parser.h:79
@ JSON_BOOLEAN_TYPE
JSON boolean datatype.
Definition: cy_json_parser.h:81
@ JSON_FLOAT_TYPE
JSON float datatype.
Definition: cy_json_parser.h:78
@ JSON_NUMBER_TYPE
JSON integer datatype.
Definition: cy_json_parser.h:74
@ JSON_STRING_TYPE
JSON string datatype.
Definition: cy_json_parser.h:73
cy_rslt_t cy_JSON_parser(const char *json_input, uint32_t input_length)
Parse the JSON data.
cy_rslt_t cy_JSON_parser_register_callback(cy_JSON_callback_t json_callback, void *arg)
Register callback to be invoked by JSON parser while parsing the JSON data.
JSON parser object.
Definition: cy_json_parser.h:101
char * value
JSON string value parsed.
Definition: cy_json_parser.h:106
uint32_t intval
JSON integer value parsed.
Definition: cy_json_parser.h:108
float floatval
JSON float value parsed.
Definition: cy_json_parser.h:109
bool boolval
JSON boolean value parsed.
Definition: cy_json_parser.h:110
uint16_t value_length
length of string value parsed
Definition: cy_json_parser.h:107
cy_JSON_type_t value_type
JSON data type of value parsed.
Definition: cy_json_parser.h:105