JSON Flatten List
Dec 6 2023 at 12:00 AM
Introduction
This filter is designed to flatten a list of items into simple key=value pairs. This functionality enables the user to transform JSON data like the following:
{
"device":
{
"readings":
[
{
"param": "V12",
"unit": "V",
"value": "0.000"
},
{
"param": "V23",
"unit": "V",
"value": "0.000"
},
...
into a more simplified representation, such as:
{
"values":
{
"V12": "0.000",
"V23": "0.000",
...
This design makes it easy to read using either the JSON Auto Mapper, or the JSON Manual Mapper. The flattened list will be incorporated into the payload’s JSON data, ensuring its availability to downstream filters for further processing.
Example Options File
{
"Devices": {
"Device1": {
"DeviceType": "Generic",
...
"Filters": [
{
"FilterType": "JsonFlattenList",
"Order": 1,
"ListPath": "device.readings",
"KeyPath": "param",
"ValuePath": "value",
"ToPropertyName": "values"
}
]
}
}
}
Property Details
Here is an overview of the parameters for configuring the JSON Flatten List filter:
Property Name | Description |
---|---|
FilterType | The value for this filter is “JsonFlattenList”. |
Order | Used to determine the process order when more than one filter has been configured. |
ListPath | The JSON path to the property containing the list to flatten. |
KeyPath | The relative JSON path to the property containing the key. Defaults to “Key”. |
ValuePath | The relative JSON path to the property containing the value. Defaults to “Value”. |
ToPropertyName | The property name of the flattened list. If this is blank, then the flattened properties will be added to the root of the original JSON document. |