Link Search Menu Expand Document

JSON Flatten List

Dec 6 2023 at 12:00 AM

  1. Introduction
  2. Example Options File
    1. Property Details

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 NameDescription
FilterTypeThe value for this filter is “JsonFlattenList”.
OrderUsed to determine the process order when more than one filter has been configured.
ListPathThe JSON path to the property containing the list to flatten.
KeyPathThe relative JSON path to the property containing the key. Defaults to “Key”.
ValuePathThe relative JSON path to the property containing the value. Defaults to “Value”.
ToPropertyNameThe 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.