Basic JSON Parser Example

Read JSON files and extract tokens

API Features Demonstrated


This app works on:

Requirements and Prerequisites

This app requires a ZentriOS device.


This app demonstrates the JSON parsing utility API.

Usage Instructions

No interaction is required. The first part of the output is as follows:

> JSON Parser demo starting...

Parsing: json/example1.json
[Closed: 0]
> JSON file contents:
Object: 2
String: markers
Array: 3
Object: 16
String: point
Array: 2
Float: 40.266044
Float: -74.718479
String: homeTeam
String: Lawrence Library
String: awayTeam
String: LUGip
String: markerImage
String: images/red.png
String: information
String: Linux users group meets second Wednesday of each month.
String: fixture
String: Wednesday 7pm
String: capacity
String: previousScore

This corresponds to the first part of the json/example1.json file:

{"markers": [
            "homeTeam":"Lawrence Library",
            "information": "Linux users group meets second Wednesday of each month.",
            "fixture":"Wednesday 7pm",
] }

After completing the sequence of parsing steps, the app exits and the device reboots.



The example source parse_example1.c is a basic JSON parsing example. It uses a statically allocated buffer for chunked reading of the JSON file.


The example source parse_example2.c demonstrates having the entire JSON string pre-read into a buffer. The json buffer is then parsed and the tokens are looked up by their string value.


The example source parse_example3.c demonstrates reading a JSON file in chunks and keeping only a subset of the tokens.

The call to json_parse_context_init passes a configuration specifying the file_reader callback and a json_token_callback function, called before a token is allocated. It tests the token for meeting certain criteria and sets values of the keys within the context structure. It returns ZOS_SUCCESS if the token is to be kept and ZOS_ABORTED if the token is to be discarded.


The example source parse_example9.c demonstrates reading nested values from a JSON structure.



See also: