JSON Manual Mapper
Dec 6 2023 at 12:00 AM
Introduction
This filter is designed to load the payload data as a JSON document. Subsequently, it creates the configured payload values by extracting the values for those properties from the specified JSON paths.
Example Options File
{
"Devices": {
"Device1": {
"DeviceType": "Generic",
...
"Filters": [
{
"FilterType": "JsonManualMapper",
"Order": 1,
"JsonType": "SingleDocument",
"TimestampPath": "Timestamp",
"TimestampType": "String",
"PropertyMaps": {
"StationId": {
"ValuePath": "StationId"
},
"OutsideTemp": {
"ValuePath": "Temperature.Outside"
},
"InsideTemp": {
"ValuePath": "Temperature.Inside"
}
}
}
]
}
}
}
JSON Path
JSON Path serves as a query language for JSON, like XPath for XML. It enables users to select a specific value from a JSON document.
The specified 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.
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 JsonManualMapper filter:
Property Name | Description |
---|---|
FilterType | Specifies that the filter is of type “JsonManualMapper”. |
Order | Used to determine the processing order when multiple filters are configured. |
ProjectId | The unique identifier of the C# project that will be compiled and used to process payloads. |
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. |
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. |
Timestamp Types
Here is an explanation of the different configurations for representing a date:
Timestamp Type | Value | Description |
---|---|---|
String | 0 | The date is represented as a string value. |
UnixTimeMilliseconds | 1 | The date is represented as the number of milliseconds since the epoch. |
UnixTimeSeconds | 2 | The date is represented as the number of seconds since the epoch. |
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 includes values for the keys GatewayId, GroupName, DeviceType, or DeviceName, those respective values will be set for the telemetry properties. However, it is important to note that any values obtained from the JSON document will overwrite these initially set values. In other words, the Source Information values for GatewayId, GroupName, DeviceType, or DeviceName function as default values, but they can be overridden by corresponding values 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,
}
}