Encode JSON

The Encode JSON action parses a JSON template and populates the identified variables into an output JSON string.


The Encode JSON action is now part of the base runtime.

Starting with the 18.2.3 release, the Encode JSON action is now part of the base runtime product.

For releases 18.2.2 and earlier, this action is part of the Technology Preview Extension, which is also referred to as the sandbox package.

Parameter descriptions

Parameter Description
JSON Template A JSON structure that will generate variables to be encoded. The JSON template contains sample values that show the variables and their types. Each JSON variable element contains the following:
  • Sample Value - The sample value is used by the deviceWISE to determine the variable type.
  • Map variable - An Input variable corresponding to a JSON template value. This variable type is determined from the Sample Value defined in the template.
  • Map variable size - The actual size of the array. This size must be greater than 0 and less than the advanced property, Maximum Array Size.

An array of values is indicated by enclosing the value within[ ] characters. If a JSON Object contains an array of values another variable is generated to specify the size.

Clicking the multi-line input icon allows you to view or edit the JSON Template.

Select the Use Advanced Properties to view the advanced properties. The following table describes the advanced properties parameters:

Parameter Description
Structure Delimiter Character(s) The character(s) that will be used to separate a structure name and the items in the structure.
Array Current Size Append Character(s)
The character(s) that will be used to name the current size input variable for an array.

Each member within a JSON structure must be represented at runtime as a unique variable. A unique name is created to identify each member in the structure. The name consists of the structure name, followed by a delimiter character, followed by the member name.

Input tab

The Input tab contains all the variables parsed from the JSON Template.

Parameter Description
Input Map Variables JSON Objects with values are identified from the JSON Template and will be added as input variables.

Output tab

Parameter Description
JSON Output The JSON string which is the result of the encoding using the JSON template and the values from the Input tab variables.
Result Status An INT4 variable that will contain the completion status of this action. A value of zero indicates the JSON Input value is successfully parsed and matched the template identified in the JSON Template field. A non-zero value indicates the action is not successful.
Result Message A String variable of 64 characters that will provide further information when the resultStatus is non-zero.
Considerations & Limitations
  • NULL values in the template are currently not supported. If there is a null value, it is ignored.
  • Floating points must not be whole numbers such as "1.0". This will register as an integer. The user must enter some decimal value like "1.9". This is a limitation of the library used.
  • This action does not support arrays and objects that are nested too deeply because this would result in a stack overflow. To prevent this the action limits the depth to JSON_NESTING_LIMIT which is 1000 by default but it is possible to change it at compile time.
  • The action template does not support strings that contain the zero character '\0' or \u0000. This is due to the fact that those strings are zero terminated.
  • This action does not officially support any double  implementations other than IEEE754 double precision floating point numbers. The maximum length of a floating point literal that the action supports is currently 63 characters.
Example

The following is an example JSON template that contains a mix of data types and includes an array of a structure named INSTALLED_PART.
The array contains two elements with members named partNamepartSerialNumberpartStatus, and timestamp

JSON Template
{
    "INSTALLED_PART": [{
            "partName": "HEADLIGHT PART",
            "partSerialNumber": "PART1",
            "partStatus": "1",
            "timestamp": "2013-10-02 14:34:31.537"
        },
        {
            "partName": "TEST PART",
            "partSerialNumber": "PART2",
            "partStatus": "1",
            "timestamp": "2013-10-0214:34:34.056"
        }
    ],
    "PRODUCT_TYPE": "FRAME",
    "PROCESS_POINT_ID": "PP10483",
    "PRODUCT_ID": "5KBRL5898EB801655",
    "TEXT_ID": "0410",
    "TIMESTAMP": "2013-10-02 13:22:42"
}

The following is the Input tab that corresponds to the above JSON template. The # character is used to delimit the structure name and the structure member name.