Technical Article

Understanding the JSON Data Format for Industrial Control Architecture

December 15, 2023 by Michael Levanduski

It is important to have some baseline understanding of JavaScript Object Notation, or JSON, one of the most common data exchange formats used in the connected industrial world today.

As we discuss various strategies for transferring data from a shop floor to a remote processor, turning it into actionable decisions, the ability to format and translate the sensor values becomes very important. One of the most common methods of data formatting for simple IoT projects is known as ‘JSON.’

 

What is JSON?

JSON stands for JavaScript Object Notation. It is a pure text-based format that resembles the structure of a JavaScript object. The text-based file, or JSON string, is defined by opening and closing curly brackets { } and contains data in the form of key/value pairs. A very simple industrial example could be the following:

{
"machine": "A"
}

 

All keys, also referred to as ‘properties,’ must be defined with double quotes. Any string-based values associated with keys also required double quotes. Single quotes used to define strings in other languages, such as Python, are not supported in JSON format. With a brief intro to what defines the JSON personality, how did it come to be, and why is it used so heavily in the world?

More importantly, why should a controls engineer know a little bit about this format?

 

JSON image icon

Figure 1. JSON art. Image used courtesy of Adobe Stock

 

The History of XML and JSON

JSON is a relatively new format that was officially born during the ‘dot-com bubble.’ This era in history was defined by web development, and by extension, the client-server architecture. As the dotcom frenzy propagated, many programmers and technologists in the space struggled with transferring data between server side applications and clients.

Already existing formats, like XML, were cognitively and computationally heavy for both humans and servers. This resulted in poor network performance and application latency. Further working against XML was perception. Large corporations had become overly eager and abused XML’s extensibility to develop overly complex toolsets and applications. By enterprise association, XML was viewed as an undesirable option. However, no other widely recognized formats officially existed at that time.

This is where the history of JSON becomes intriguing. While a man named Douglas Crockford is credited with garnering the community, documentation, and widespread recognition of the format, it existed possibly a decade before.

Many scrappy, adaptable programmers had figured out the benefits of mirroring the JavaScript object structure in string format for data transfer. An innovation forged from the pain of exercising clunky, headache-inducing XML-based tools. The majority, unbeknownst to each other, had arrived at the same conclusion as their peers. And that is why JSON is one of the most widely used data exchange formats today: it is simple and cognitively lighter than XML.

 

Industrial Context

Even though JSON is used primarily in traditional web development, it is also used extensively in the world of control automation. Low-capability edge or gateway devices transmitting IIoT data benefit from the efficiency of JSON. The responsiveness and low latency of SCADA systems and dashboards for plant monitoring and asset management are in part enabled by the JSON format. It is not visible to the front-end application that the control engineer generally sees, but it is very alive and essential in the background.

 

Sample IIoT network

Figure 2. The backend of modern IIoT is powered by JSON. Image used courtesy of Adobe Stock

 

Data Types

Does JSON lose some extensibility in favor of simplicity? Yes, but it is by no means restrictive. The values associated with properties are not solely limited to the string data type. Value data types can also include array, object, boolean, number, and null types.

 

Array Type

This data type is an ordered set of values contained within opening and closing brackets [ ]. Values within an array can be mixed, they do not need to be all of the same type. Values are separated by commas. An array is analogous to a list in Python.

{
"machine": 1,
"parameters": ["Temperature", "Pressure"]
}

 

Object Type

An object is analogous to a Python dictionary and is composed of key/value pairs enclosed within opening and closing curly brackets { }. The keys must be of string type, and respective values are distinguished by use of a colon. Separation of key/value pairs is achieved by using commas.

{
    "machine": 1,
    "parameters": {
        "temperature": 40, 
        "pressure": 456,
        "configuration": "A"
    }
}

 

Boolean

The 0 or 1 condition of boolean logic can be represented by true or false.

{
"machine": 1,
"isActive": false,
"isInMaintenance": true
}

 

Number

Numbers in JSON can be represented by negative and positive integers, floating point numbers, and even exponential notation (e+, e-, E+, or E-).

{
"machine": 1,
"asset number": 345,
"cost": 52345.56
}

 

Data Transfer and Parsing

A great feature of JSON is its language-agnostic capability. Even though it is modeled after JavaScript objects, it exists as a string data type. This makes data transfer across networks from system to system easy and lightweight. When it comes to receiving and parsing the JSON payload within the destination system, there are many options available.

Generally, the process of “unpacking” the payload involves deserialization. This means that the JSON string is converted into the destination system's native data type. For example, in Python, an ingested JSON string can be deserialized into a native Python dictionary data type. This process uses the built-in JSON library loads method like below.

import json
 
json_string = '{"machine": 1, "parameters": ["temperature", "pressure"],"OEE": 0.76}'
 
print("Datatype before deserialization : "
      + str(type(json_string)))
  
json_deserialized = json.loads(json_string)
 
print("Datatype after deserialization : "
      + str(type(json_deserialized)))

 

The output of this dummy script will show how the data types have been converted by the json.loads method.

mlevanduski@Michaels-MBP test % python3 jsonTest.py
Datatype before deserialization : <class 'str'>
Datatype after deserialization : <class 'dict'>

 

Parsing of JSON keys or properties to obtain associated values can be performed by parsing the dictionary object. Following the above example, adding the following line of code, saving, and re-running the script will demonstrate parsing capability.

print("The machine key value is: " + str(json_deserialized['machine']))

 

The result of which is.

Datatype before deserialization : <class 'str'>
Datatype after deserialization : <class 'dict'>
The machine key value is: 1

 

Why is JSON Used for IIoT?

JSON is an invention born out of necessity and ingenuity in the early days of the internet. It has stood the test of time due to its simplicity, effectiveness, and versatility. In today’s world, it serves as a very common and popular data exchange format used to facilitate the transfer of data in the industrial controls and IoT sector.