json_app

Table of Contents

Example Summary

This example demonstrates the use of the JSON library.

The app enables the user to use all the JSON parsing and building APIs.

Example Usage

#define TEMPLATE_FILENAME “template1”

#define JSON_FILENAME “json1”

The connection should have the following connection settings:

Baud-rate:    115200
Data bits:         8
Stop bits:         1
Parity:         None
Flow Control:   None
    

Once the application has complete it’s initialization and the network processor is up,
the application banner would be displayed, showing version details:

 ==============================================
    JSON Parser & Builder Example Ver: 1.0.0
 ==============================================

 CHIP: 0x20000010
 MAC:  2.0.0.0
 PHY:  2.2.0.4
 NWP:  3.3.0.0
 ROM:  0
 HOST: 2.0.1.15
 MAC address: 08:00:28:5b:55:e3

 ==============================================

Scenarios examples

The scenario examples are written in high level using the json lib APIs.

 Create json from       | Parse the json and get | Parse the json, change
 scratch and build it   | its value              | its value and build it
 +--------------------+ | +--------------------+ | +--------------------+
 |Json_createTemplate | | |Json_createTemplate | | |Json_createTemplate |
 +--------------------+ | +--------------------+ | +--------------------+
            |           |            |           |            |
            v           |            v           |            v
 +--------------------+ | +--------------------+ | +--------------------+
 |Json_createObject   | | |Json_createObject   | | |Json_createObject   |
 +--------------------+ | +--------------------+ | +--------------------+
            |           |            |           |            |
            v           |            v           |            v
 +--------------------+ | +--------------------+ | +--------------------+
 |Json_setValue       | | |Json_parse          | | |Json_parse          |
 +--------------------+ | +--------------------+ | +--------------------+
            |           |            |           |            |
            v           |            v           |            v
 +--------------------+ | +--------------------+ | +--------------------+
 |Json_build          | | |Json_getValue       | | |Json_getValue       |
 +--------------------+ | +--------------------+ | +--------------------+
            |           |            |           |            |
            v           |            v           |            v
 +--------------------+ | +--------------------+ | +--------------------+
 |Json_destroyObject  | | |Json_destroyObject  | | |Json_setValue       |
 +--------------------+ | +--------------------+ | +--------------------+
            |           |            |           |            |
            v           |            v           |            v
 +--------------------+ | +--------------------+ | +--------------------+
 |Json_destroyTemplate| | |Json_destroyTemplate| | |Json_build          |
 +--------------------+ | +--------------------+ | +--------------------+
                        |                        |            |
                        |                        |            v
                        |                        | +--------------------+
                        |                        | |Json_destroyObject  |
                        |                        | +--------------------+
                        |                        |            |
                        |                        |            v
                        |                        | +--------------------+
                        |                        | |Json_destroyTemplate|
                        |                        | +--------------------+     

Application Design details

Json file and Json template examples

Json template example

{
  "firstName": string,
  "lastName": string,
  "isAlive": boolean,
  "age": int32,
  "address": {
    "streetAddress": string,
    "city": string,
    "state": string,
    "postalCode": string
  },
  "phoneNumbers": [
    {
      "type": string,
      "number": string
    },
    {
      "type": string,
      "number": string
    },
    {
      "type": string,
      "number": string
    }
  ],
  "children": [raw],
  "spouse": boolean
}

Json file example

{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 25,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    },
    {
      "type": "mobile",
      "number": "123 456-7890"
    }
  ],
  "children": [],
  "spouse": null
}