Exporting with a JSON schema

Adding a JsonSchema component to your station allows for the construction of a JSON payload to suit the requirements of your particular application.

Overview

There are examples in the jsonToolkit palette, which may help with learning how to construct a schema. You can simply drag the JsonExampleComponents and Schemas folders into a running station to work with them.

Figure 5.   Schema parts
Image

You construct a schema by placing “entities” from the jsonToolkit palette below a JsonSchema in the station and then use configuration properties and queries to get the output you want. Use the numbers in the screen capture to learn about schema elements:

  1. You can give each schema a unique name.
  2. The Output property contains the resulting JSON payload (message or string).
     
    NOTE: The format of this black box (with new lines and spacing) is purely for presentation. The actual string output is minified and does not contain extra spaces.
     
  3. The Enabled property turns the generation of output, execution of queries and subscription to bound values on and off. The Config folder contains properties that configure general schema attributes.
  4. The Queries folder can contain query entities to insert bql, historical or alarm database content into a payload.
  5. A { } root object or an [ ] array contains JSON entities that structure the Output message. Some entities may be simple—for example braces { } represent a simple JSON object, while other entities represent Niagara bql queries (refer to the Niagara Developer Guide) and, therefore, have the potential to be more complex.
  6. Actions build and manage schema contents. The Generate action builds and updates schema output. For relative schemata, Generate evaluates the base query and publishes the results for each resolved base item.

What can a Schema contain?

The schema supports a nested structure of child entities. These can be Objects, Arrays, or Properties of various types. Niagara alarm, history or point data may populate these entities, which include:
Entity Type Output
Object “objectName” :{"name” : value, “name2” : value2….}
Array “arrayName” :[value, value2….]
Property “key”: value
Property List “key”: value, “key2”: value2

All entities (minus Property) support nested child entities. This lets you build a schema using a tree structure with entities found in the jsonToolkit palette.

What structure is allowed?

Every schema requires a root member that is allowed by the JSON standard: this means an object { } or an array [ ].

Figure 6.   root Json Schema Object
Image

The screen capture shows how Niagara represents a JSON root object in a standard Property Sheet view.