Constructing the JSON Configuration

About this task

Construct a JSON configuration object that contains the Python expression in the same text editor. This allows you to specify Python modules that you require and to link the variables (parameters) used in the expression to a raw data source.

It is easier to edit your JSON in the Historian Excel Add-In, which you will use later to add the tag to Historian, see Adding a Python Expression Tag to Historian.

The JSON needs to be ?minified ? and it needs to conform to a particular structure. Example of JSON containing a Python Expression in "Minified" format

{"imports":["math"],"script":"temp.value + 
math.pow(10,temp.value/70)","parameters":[{"name":"temp","source":{"add
Here is an example of JSON structure in ?Beautified ? format. The highlighted entries are placeholders.
{
"imports":["<imported_module0>", "<imported_module1>", 
"<imported_module2>",...], "script":"<python_expression>",
"parameters":[
{
"name":"<variable_name>", "source":{"address":"<source_address>",
"dataType":"<datatype_of_parameter_value_field>"}
},...
]
}

After "imports", list the Python modules you need to import for your Python expression. See Supported Python Modules.

After "script", enter the python expression that you created in Constructing a Python Expression.

Provide values for the following parameters:
ParameterDescription
nameThe variable name you gave to the object representing the raw data which will be pre-processed by the expression you created. This variable is exposed in the Python script as an object with the following properties: value, is_quality_good, is_quality_bad, timestamp.
addressThe source address used by the collector to access the raw data. This parameter is stipulated in the context of the chosen collector, which must be on the list of collectors supporting Python Expression Tags.
dataTypeThe datatype of the \value field for the variable representing the raw data. This allows the Python expression to know the data type on which it is operating.

The datatype options are: SingleFloat, DoubleFloat, SingleInteger, DoubleInteger, QuadInteger, UnsignedSingleInteger, UnsignedDoubleInteger, UnsignedQuadInteger, FixedString, VariableString, Byte, Boolean. These are the same Historian data types that are supported by the File Collector.

Example of JSON containing a Python Expression in ?Beautified ? format

This example uses the Simulation Collector. Your collector might use a different source address.
{
 "imports":["math"],
 "script":"temp.value+math.pow(10,temp.value/70)",
 "parameters":[{"name":"temp","source":
{"address":"Simulation00001","dataType":"SingleFloat" } } ]
}

It is important to check that your JSON is valid, since no validation will be performed on the JSON at tag creation.

Minified JSON

Once you have constructed this JSON, you need to format it as a ?minified ? string, so that it can be processed in later steps. Minified JSON has no newline characters or comments. There are tools which can help you minify JSON.

For our example, the minified JSON would look like this:
{"imports":["math"],"script":"temp.value + math.pow(10,temp.value/70)","parameters":
[{"name":"temp","source":{"address":"Simulation00001","dataType":"SingleFloat"}}]}

Pay attention to escape characters in your JSON. If your JSON contains a \ character, you need to escape it. So, \ becomes \\ (since \ is used to escape another \).