Link Search Menu Expand Document

JSON Manual Mapper

Dec 6 2023 at 12:00 AM

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

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 NameDescription
FilterTypeSpecifies that the filter is of type “JsonManualMapper”.
OrderUsed to determine the processing order when multiple filters are configured.
ProjectIdThe unique identifier of the C# project that will be compiled and used to process payloads.
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.

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.

Timestamp Types


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

Timestamp TypeValueDescription
String0The date is represented as a string value.
UnixTimeMilliseconds1The date is represented as the number of milliseconds since the epoch.
UnixTimeSeconds2The 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 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 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, 
  }
}