basic/json_parser/parse_example9.c
See examples/basic/json-parser
/*
* ZentriOS SDK LICENSE AGREEMENT | Zentri.com, 2015.
*
* Use of source code and/or libraries contained in the ZentriOS SDK is
* subject to the Zentri Operating System SDK license agreement and
* applicable open source license agreements.
*
*/
#include "zos.h"
/*************************************************************************************************
* This demonstrates reading nested values from a JSON structure.
*
*
* The parsed JSON looks like:
*
{
"name": "Product",
"properties": {
"id": {
"type": "number",
"description": "Product identifier",
"required": true
},
"name": {
"description": "Name of the product",
"type": "string",
"required": true
},
"price": {
"type": "number",
"minimum": 0,
"required": true
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
*
*
*/
{
zos_result_t result;
json_parse_context_t *context = NULL;
char *json_data = NULL;
{
ZOS_LOG("Failed to read: %s", filename);
return result;
}
{
.buffer = json_data,
.buffer_len = strlen(json_data)
};
{
ZOS_LOG("Failed to initialize json parsing context");
}
{
ZOS_LOG("Failed to parse json file");
}
else
{
if(prop != NULL)
{
if(prop_tags != NULL)
{
if(prop_tags_type != NULL)
{
}
else
{
ZOS_LOG("Failed to get properties.tags.type token");
}
if(prop_tags_items != NULL)
{
if(prop_tags_items_type != NULL)
{
}
else
{
ZOS_LOG("Failed to get properties.tags.items.type token");
}
}
else
{
ZOS_LOG("Failed to get properties.tags.items token");
}
}
else
{
ZOS_LOG("Failed to get properties.tags token");
}
}
else
{
ZOS_LOG("Failed to get properties token");
}
}
json_parse_context_deinit(context);
if(json_data != NULL)
{
zn_free(json_data);
}
ZOS_LOG("Finished");
return result;
}
/*************************************************************************************************
* Pre-read the JSON file into a buffer
*/
{
zos_result_t result;
uint32_t handle;
uint8_t *ptr;
{
}
{
}
{
}
{
}
else
{
ptr[fd.file_size] = 0; // null-terminate string
*buffer = (char*)ptr;
}
return result;
}