Link Search Menu Expand Document

JSON Auto Mapper

Dec 6 2023 at 12:00 AM

  1. Introduction
  2. Example Options File
  3. JSON Path
    1. Property Details
    2. Timestamp Type
    3. Property Map
    4. Value Sources
    5. Dictionary Key Types
  4. Source Information
  5. JSON Types

Introduction

This filter is designed to load the payload data as a JSON document and traverse through the document. During this process, it automatically incorporates all the encountered JSON properties into the payload values.

Example Options File

{
  "Devices": {
    "Device1": {
      "DeviceType": "Generic",
      ...
      "Filters": [
         {
            "FilterType": "JsonAutoMapper",
            "Order": 1,
            "JsonType": "SingleDocument",
            "TimestampPath": "Timestamp",
            "TimestampType": "String"
         }
      ]
    }
  }  
}

JSON Path

JSON Path serves as a query language for JSON, like XPath for XML. It enables the user to select a specific value from a JSON document.

The required JSON path depends on the specified JSONType:

  • SingleDocument: The JSON path is relative to the entire document.
  • DocumentArray: The JSON path is relative to the array element.
  • Dictionary: The JSON path is relative to the array element.

For an accessible way to obtain the JSON path for a required value, users can use the JSON Path Online Evaluator.

Property Details


Here is an overview of the parameters for configuring the JsonAutoMapper filter:

Property NameDescription
FilterTypeSpecifies that the filter is of type “JsonAutoMapper”.
OrderUsed to determine the processing order when multiple filters are configured.
JsonTypeDefines the type of data contained in the JSON serialized string. Refer to the section below.
DictionaryKeyTypeDefines what the dictionary key value is. This is only relevant when JsonType is set to “Dictionary”. Refer to the section below. Defaults to “DeviceName”.
IgnoreDictionaryKeysList of dictionary keys (strings) to ignore. This is only relevant when JsonType is set to “Dictionary”.
RootBasePathThe path to the base of each root document. It is from this base that all other paths are relative to. Defaults to blank.
TimestampPathThe JSON path for the telemetry UTC timestamp property value. If this is blank, then the current UTC time will be used.
TimestampTypeThe type of dates in the timestamp property. Refer to the section below.
GatewayIdPathThe JSON path for the property value used for the gateway Id. If this is blank, then the configured gateway Id will be used.
GroupNamePathThe JSON path for the property value used for the group name. If this is blank, then the configured group name will be used.
DeviceTypePathThe JSON path for the property value used for the device type. If this is blank, then the configured device type will be used.
DeviceNamePathThe JSON path for the property value used for the device name. If this is blank, then the configured device name will be used.
PropertyMapsDictionary of properties to create, where the property map key is the property name.

Timestamp Type


Here is an explanation of the different configurations for representing a date:

Timestamp TypeValueDescription
String0The date is a string value.
UnixTimeMilliseconds1The date is the number of milliseconds since epoch.
UnixTimeSeconds2The date is the number of seconds since epoch.

Property Map


Here are the configurations for defining a property:

Property NameDescription
DataTypeSpecifies the data type. If left blank, the data type will be inferred from the JsonPath value.
TransformSetIdThe ID of the Transform Set used to transform this property value.
ValueSourceIndicates the source of the value. Defaults to “JsonDocument”.
ValuePathThis depends on the ValueSource type. It will either be:
1. the JSON Path to the value in the JSON document relative to the document root path.
2. the key to the Source Information value.
IgnoreSet this to true to ignore this Property, preventing it from being loaded when the filter is executed.
ArrayDelimiterIf the value is an array, this specifies the delimiter used to convert the value to a string.

Value Sources


Here are the configurations for obtaining a value:

Value SourceValueDescription
JsonDocument0The value is extracted from the JSON document.
SourceInfo1The value is obtained from the Source Information.

Dictionary Key Types


A breakdown of the possible configurations for a specific key, based on the provided values:

Key TypeValueDescription
None0The key is ignored.
DeviceName1The key represents the device name.
DeviceType2The key represents the device type.
GroupName3The key represents the group name.
GatewayId4The key represents the gateway identifier.

Source Information

If the Source Information provides values for the keys GatewayId, GroupName, DeviceType, or DeviceName, these respective values will be applied to the telemetry properties. However, it is important to note that any values retrieved from the JSON document will take precedence and overwrite these initial values. In other words, the Source Information values for GatewayId, GroupName, DeviceType, or DeviceName function as default values, subject to being overridden by corresponding values extracted from the JSON document.

JSON Types

0 = SingleDocument

The JSON contains a single root document.

{
  "StationId": "Station123",
  "Timestamp": "2022-09-28T15:58:00+02:00",
  "Temperature": {
    "Outside": 30.3,
    "Inside": 25.8
  },
  "WindSpeed": 20,
  "Humidity": 56.34,
  "Location": {
    "Lat": -25.863164,
    "Lon": 28.2084316
  }
}

1 = DocumentArray

The JSON contains an array of root documents.

[
  {
    "Timestamp": 1664373219,
    "Temp": 23,
    "Location": {
      "Lat": -25.863164,
      "Lon": 28.2084316
    }
  },
  {
    "Timestamp": 1664373220,
    "Temp": 24,
    "Location": {
      "Lat": -25.863164,
      "Lon": 28.2084316
    }
  }
]

2 = Dictionary

The JSON contains a dictionary of root documents. The dictionary key can be used to set a value (e.g. DeviceName).

{
  "Device1": {
    "Timestamp": 1664373219,
    "Temp": 23
  },
  "Device2": {
    "Timestamp": 1664373219,
    "Temp": 23, 
  }
}