JSON Auto Mapper
Dec 6 2023 at 12:00 AM
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 Name | Description |
---|---|
FilterType | Specifies that the filter is of type “JsonAutoMapper”. |
Order | Used to determine the processing order when multiple filters are configured. |
JsonType | Defines the type of data contained in the JSON serialized string. Refer to the section below. |
DictionaryKeyType | Defines what the dictionary key value is. This is only relevant when JsonType is set to “Dictionary”. Refer to the section below. Defaults to “DeviceName”. |
IgnoreDictionaryKeys | List of dictionary keys (strings) to ignore. This is only relevant when JsonType is set to “Dictionary”. |
RootBasePath | The path to the base of each root document. It is from this base that all other paths are relative to. Defaults to blank. |
TimestampPath | The JSON path for the telemetry UTC timestamp property value. If this is blank, then the current UTC time will be used. |
TimestampType | The type of dates in the timestamp property. Refer to the section below. |
GatewayIdPath | The JSON path for the property value used for the gateway Id. If this is blank, then the configured gateway Id will be used. |
GroupNamePath | The JSON path for the property value used for the group name. If this is blank, then the configured group name will be used. |
DeviceTypePath | The JSON path for the property value used for the device type. If this is blank, then the configured device type will be used. |
DeviceNamePath | The JSON path for the property value used for the device name. If this is blank, then the configured device name will be used. |
PropertyMaps | Dictionary 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 Type | Value | Description |
---|---|---|
String | 0 | The date is a string value. |
UnixTimeMilliseconds | 1 | The date is the number of milliseconds since epoch. |
UnixTimeSeconds | 2 | The date is the number of seconds since epoch. |
Property Map
Here are the configurations for defining a property:
Property Name | Description |
---|---|
DataType | Specifies the data type. If left blank, the data type will be inferred from the JsonPath value. |
TransformSetId | The ID of the Transform Set used to transform this property value. |
ValueSource | Indicates the source of the value. Defaults to “JsonDocument”. |
ValuePath | This 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. |
Ignore | Set this to true to ignore this Property, preventing it from being loaded when the filter is executed. |
ArrayDelimiter | If 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 Source | Value | Description |
---|---|---|
JsonDocument | 0 | The value is extracted from the JSON document. |
SourceInfo | 1 | The 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 Type | Value | Description |
---|---|---|
None | 0 | The key is ignored. |
DeviceName | 1 | The key represents the device name. |
DeviceType | 2 | The key represents the device type. |
GroupName | 3 | The key represents the group name. |
GatewayId | 4 | The 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,
}
}