Encode JSON (new)

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


The new Encode JSON action is a part of the dwjson 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) 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. The default character used to delimit between the structure name and the variable within the structure is the # character. This parameter can be used to change this value to another character.
Array Current Size Append Character(s)
The character(s) that will be used to name the current size input variable for an array.
Maximum String Size The maximum length of the strings in an array that can be contained within a JSON variable. A default maximum string size of 256 is used for all variables on the Output tab that have a data type of String.
Maximum Array Size The maximum length of arrays.
Missing Properties Use template: When you select this option, the resulting output JSON will contain the values from the template for the items that you did not provide values for, the value should be set to the one provided in the template.
Set to NULL: When you select this option, the items for which you did not provide input values will have a value of null in the output JSON string.
Ignore: When you select this option, the items for which you did not provide input values will not appear in the output JSON string.

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.