utility/json_parser/parse_example9.c
/*
* EVALUATION AND USE OF THIS SOFTWARE IS SUBJECT TO THE TERMS AND
* CONDITIONS OF THE CONTROLLING LICENSE AGREEMENT FOUND AT LICENSE.md
* IN THIS SDK. IF YOU DO NOT AGREE TO THE LICENSE TERMS AND CONDITIONS,
* PLEASE RETURN ALL SOURCE FILES TO SILICON LABORATORIES.
* (c) Copyright 2018, Silicon Laboratories Inc. All rights reserved.
*/
#include "gos.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"
}
}
}
}
*
*
*/
{
gos_result_t result;
gos_json_parse_context_t *context = NULL;
char *json_data = NULL;
{
GOS_LOG("Failed to read: %s", filename);
return result;
}
{
.buffer = json_data,
.buffer_len = strlen(json_data)
};
{
GOS_LOG("Failed to initialize json parsing context");
}
{
GOS_LOG("Failed to parse json file");
}
else
{
if (prop != NULL)
{
if (prop_tags != NULL)
{
if (prop_tags_type != NULL)
{
}
else
{
GOS_LOG("Failed to get properties.tags.type token");
}
if (prop_tags_items != NULL)
{
if (prop_tags_items_type != NULL)
{
}
else
{
GOS_LOG("Failed to get properties.tags.items.type token");
}
}
else
{
GOS_LOG("Failed to get properties.tags.items token");
}
}
else
{
GOS_LOG("Failed to get properties.tags token");
}
}
else
{
GOS_LOG("Failed to get properties token");
}
}
gos_json_parse_context_deinit(context);
gos_free(json_data);
GOS_LOG("Finished");
return result;
}
/*************************************************************************************************
* Pre-read the JSON file into a buffer
*/
{
gos_result_t result;
uint8_t *ptr;
{
}
{
}
{
}
{
}
else
{
ptr[fd.size] = 0; // null-terminate string
*buffer = (char*)ptr;
}
return result;
}