utility/json_parser/parse_example9.c
/*******************************************************************************
* # License
* Copyright 2019 Silicon Laboratories Inc. www.silabs.com
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
#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;
}