Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Home
  • Knowledge base
  • Contact Us
  • Home
  • Scripting & Variables
  • Data formatting

Bulking multiple data items into a JSON message

How to create a JSON messages which bulks multiple data items together in a single message

Written by Mads Mikkelsen

Updated at April 2nd, 2024

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Installation & Technical information
    Introduction SIA Connect Standalone SIA Connect ANY-Ware Cellular & WiFi connectivity
  • Configuration in the Web UI
    Getting started with the UI Connectors Instances Items Mapping Data System Network Tools & Add-ons DigiCert IoT Trust Manager
  • Connectors
    Siemens S7 Azure IoT Ethernet/IP Mitsubishi MELSEC OPC-UA Server SQL MQTT Omron Host Link REST API Omron FINS Keyence Beckhoff TwinCAT BACnet Virtual OPC-UA Client MS SQL File M-Bus Modbus
  • Scripting & Variables
    Data formatting
  • Developers
    API documentation Shadow API
  • Tutorials & Guides
    InfluxDB AWS IoT Core - Amazon Web Services Microsoft Power BI KaaIoT Siemens S7 AVEVA Insight SIA Connect Demo Rack Grafana Azure
  • General
+ More

Table of Contents

📽️ Video instruction Defining a custom structure for the JSON message Applying the structure of the JSON message Setting the input template to the JSON message Setting JSON message individually per mapping Example video

This article will demonstrate how to bulk various data items into a single JSON message which can be used as payload for IT communication Connectors such as MQTT & REST API's.

To get started you will need to add an Instance together with data Items to be bulked and wrapped into the JSON message.

 

📽️ Video instruction

Go to the bottom of the article to check out the video instructions for how to apply data formatting to an Item with Input template

 

 

 

Defining a custom structure for the JSON message

The first thing to decide is the structure of the JSON payload which might either be of your choice or dependent on the other system (such as a cloud service) who is going to receive the data.

In this example we assume we have an Instance called AB_xyz_PLC with a set Items as follows:

Instance: AB_XYZ
Item name (or UID) Value
Temperature 21°
Pressure 10 kPa
Humidity 50 %RH
Speed 1200 Hz
Level 1500 cm

 

Now we know what data to include in the message, let's define how we want our JSON message to be:

{
	"%TEMPERATURE.NAME%": "%TEMPERATURE.VALUE%",
	"%PRESSURE.NAME%": "%PRESSURE.VALUE%",
	"%HUMIDITY.NAME%": "%HUMIDITY.VALUE%",
	"%SPEED.NAME%": "%SPEED.VALUE%",
	"%LEVEL.NAME%": "%LEVEL.VALUE%",
	"time": "%VALUE.TIME%"
}

The above format can be edited and structured in any way that suites your JSON format. Any JSON format is supported including arrays. 
You can find a list of all system and items variables at the following articles:

  • System variables 
  • Instance variables 
  • Item variables 

 

Above would translate into something like when receiving the topic at the MQTT broker:

{
	"Temperature": "21",
	"Pressure": "10",
	"Humidity": "50",
	"Speed": "1200",
	"Level": "1500",
	"time": "2024-04-02T12:00:00"
}

 

 

Applying the structure of the JSON message

Next step is to apply the structure of your custom JSON message to the messages being transmitted from the edge and into the system which requires the JSON message (MQTT, REST API, etc).

This can be achieved in two ways:

  • Setting a default input template  for the items to receive the data.
  • Adding it as custom template for a mapping

 

Setting the input template to the JSON message

To set a default data format for a item the Input template parameter in the mapping can be used. This will be the default format of the data unless other is specified in the mapping. 

The Input template needs to be set for the Item which is going to receive the data. In this example an MQTT topic.
To do so, follow the below steps:

  • Go to   Instances and select the desired Instance by clicking   
  • In the  Items list click on the items which need to receive the data in the given format. In this example it is our MQTT topic which needs to transform the data from a mapping into the given format.
  • Set the Input template to be JSON format which you defined in previous section such as
    { "%TEMPERATURE.NAME%": "%TEMPERATURE.VALUE%", "%PRESSURE.NAME%": "%PRESSURE.VALUE%", "%HUMIDITY.NAME%": "%HUMIDITY.VALUE%", "%SPEED.NAME%": "%SPEED.VALUE%", "%LEVEL.NAME%": "%LEVEL.VALUE%", "time": "%VALUE.TIME% }
  • Press  Save

 

Use the Input template of the Item if the data formatting is the same across all mappings

 

 

 

Setting JSON message individually per mapping

Data formatting can also be done individually on each mapping by setting the Custom value in the mapping.
To apply individually data formatting of each mapping follow the below steps:

  • Go to   Instances and select the desired Instance by clicking    of either the sending or receiving Instance to find or add the mapping
  • In  Mappings list click on the mapping which needs to format the data. In this example it is our MQTT mapping which needs to transform the data from a mapping into the given format.
  • Set the Custom value to be JSON format which you defined in previous section such as
    { "%TEMPERATURE.NAME%": "%TEMPERATURE.VALUE%", "%PRESSURE.NAME%": "%PRESSURE.VALUE%", "%HUMIDITY.NAME%": "%HUMIDITY.VALUE%", "%SPEED.NAME%": "%SPEED.VALUE%", "%LEVEL.NAME%": "%LEVEL.VALUE%", "time": "%VALUE.TIME% }
  • Press  Save mapping

 

Use Custom value in the Mapping if a Items has multiple Mappings as receiver where the data needs individually formatted. As Sender Item select the Item which defines when to execute the mapping e.g. transmit data to the MQTT broker

 

 

 

Example video

Check out below video to how a MQTT broker and topic is configured to use the Input template to format the data streams to the topic.

In this example we have some simulated data with the items parameters given in the section “Defining a custom structure for the JSON message”. The MQTT broker is a test broker with a topic under sia_connect/example_data_formatting/%UUID% where %UUID% is the UUID of the SIA Connect unit.

 

Your browser does not support HTML5 video.

 

data aggregation json generation item bulking message formatting data contextualize json payload json message data format

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

0
0
Expand