Skip to main content
Version: 8.1

JSON Format

About JSON

JavaScript Object Notation (JSON) is a language-independent data format. It's a lightweight format for storing and transporting data (i.e., when data is sent from a server to a web page). JSON is easy for users to read and write and for machines to parse and generate.

JSON Rules

JSON has a few simple rules:

  • Data is in name/value pairs.
  • Data is separated by commas.
  • Curly braces hold objects.
  • Square brackets hold arrays.

How JSON Works

JSON Data - Name and a Value

JSON data is written as name/value pairs. A name/value pair consists of a field name in double quotes, followed by a colon, followed by a value.

{
"companyName":"Inductive Automation"
}

JSON Objects

JSON objects are written inside curly braces.

note

The properties of a JSON object have no defined order. If you need a defined order, use a dataset or an array instead.

{
"firstName":"Sally",
"lastName":"Smith"
}

JSON Arrays

JSON Arrays are written inside square brackets. An array can contain objects. In the following example, the object "companies" is an array and contains three objects.

{ 
"companies":[
{
"companyName":"Inductive Automation",
"cityName":"Folsom",
"stateName":"CA"
},
{
"companyName":"Hewlett Packard",
"cityName":"Palo Alto",
"stateName":"CA"
},
{
"companyName":"Apple",
"cityName":"Cupertino",
"stateName":"CA"
}
]
}

Where JSON Is Used in Ignition

Ignition uses the JSON format to store much of its data internally, including Tags and Perspective component properties.

Perspective Component Properties

Components have properties (props), which are simply named values. These properties are arranged in a tree structure following the structure and data model of the common JSON document format. Component properties are defined as a JSON structure, and are variable according to the type of component that the config object represents. All components registered in the module have a set of default properties included. These defaults are provided to the instantiated component at runtime, and so default props are not saved. Instead, only those which have a value that differs from the default are stored, serialized and sent to the client during loading.

Component Property Example in JSON Format:

Example - Sample Data from Table Component
[ { "city": "Helsinki", "country": "Finland", "population": 635591 }, { "city": "Jakarta", "country": "Indonesia", "population": 10187595 }, { "city": "Madrid", "country": "Spain", "population": 3233527 }, { "city": "Prague", "country": "Czech Republic", "population": 1241664 }, { "city": "San Diego", "country": "United States", "population": 1406630 }, { "city": "Tunis", "country": "Tunisia", "population": 1056247 } ]

Tags

Ignition exports and imports Tag configurations to and from JSON. Tags are defined as JSON objects, which consist of properties, arrays, and sub-objects. The system.tag.configure function can take either a String document definition, or a JSON object that defines one or more Tags. Overrides for UDTs are created by simple redefinition of properties, and complex structures like Event Scripts and Alarm configurations will be merged with inherited definitions.

You can copy the JSON or one or or more Tags in the Tag Browser. This copies them into the system clipboard. In addition, pasting the JSON into a different provider/designer will create or overwrite tags.

Tag Export Examples in JSON Format:

Example 1 - Tag Export
{
"name": "Tank Instance",
"typeId": "Tank UDT",
"tagType": "UdtInstance",
"tags": [
{
"value": "80",
"name": "Tank Level",
"tagType": "AtomicTag"
},
{
"value": 80,
"name": "sliderValue",
"tagType": "AtomicTag"
}
]
}
Example 2 - Tag Export
{
"tags": [
{
"valueSource": "memory",
"dataType": "Boolean",
"alarms": [
{
"setpointA": 1,
"name": "Above Normal"
}
],
"name": "Boolean Tag",
"value": false,
"tagType": "AtomicTag"
},
{
"valueSource": "memory",
"dataType": "Boolean",
"name": "One Shot Trigger",
"tagGroup": "Driven One Shot",
"value": true,
"tagType": "AtomicTag",
"enabled": true
},
{
"valueSource": "opc",
"opcItemPath": "ns\u003d1;s\u003d[Generic]_Meta:Random/RandomDouble1",
"dataType": "Float8",
"name": "Pressure3",
"tagGroup": "Driven One Shot",
"tagType": "AtomicTag",
"enabled": true,
"opcServer": "Ignition OPC UA Server"
},
{
"valueSource": "opc",
"opcItemPath": "ns\u003d1;s\u003d[Generic]_Meta:Random/RandomDouble2",
"dataType": "Float8",
"name": "Thickness3",
"tagGroup": "Driven One Shot",
"tagType": "AtomicTag",
"opcServer": "Ignition OPC UA Server"
}
]
}

JSON in Tag UDTs

You can also set JSON strings as properties in an Ignition Tag. Any properties of a Tag can be set to a string that represents a JSON object.

note

In a UDT, the { } braces are used to denote a property reference. Make sure you don't have any properties with names that look like JSON objects so there is no overlap. Strings will appear as black text, parameter references will appear as grey and italicized.

Looping through JSON Objects with Scripting

Traversing a JSON object in scripting is simple as long as the structure is known. If there are objects within objects, you can use multiple loops to get through it all.

Let's use the JSON Array object above for a simple example. You can loop through the list to get the repeating items by name.


# loop through the JSON data
# fetch the data, this will change depending on where the script is in relation to the table
json = self.items
# access the companies object (which is a list)
companies = json["companies"]

# loop through the companies list
for company in companies :
# get each item out of the row object
name = company["companyName"]
city = company["cityName"]
state= company["stateName"]
# now do something with the data