Documentation Index

Fetch the complete documentation index at: https://docs.supermetrics.com/llms.txt

Use this file to discover all available pages before exploring further.

Flatten values

Prev Next

For each item at dataPath, the flatten_values adapter takes the nested array at valuesPath and produces one new row per array entry. The parent fields are copied onto every resulting row, and the nested keys are renamed by prefixing them with the last segment of valuesPath.

Field Type Required Description
dataPath string Yes JSONPath to each item that contains the nested array.
valuesPath string Yes JSONPath, relative to each item, to the array whose entries should become separate rows.

Below you can find a before/after example. The original response has a single metrics row per day with hourly activity inside it:

{
  "data": {
    "metrics": [
      {
        "date": "2022-12-30",
        "audience_activity": [
          { 
            "hour": "0", 
            "count": 28 
          },
          { 
            "hour": "1",
            "count": 20
          }
        ]
      }
    ]
  }
}

After the adapter runs, each hour becomes its own row, with the date copied across and the nested keys prefixed:

{
  "data": {
    "metrics": [
      { 
        "date": "2022-12-30",
        "audience_activity_hour": "0",
        "audience_activity_count": 28
      },
      { 
        "date": "2022-12-30",
        "audience_activity_hour": "1", 
        "audience_activity_count": 20
      }
    ]
  }
}

Configuration:

"response": {
  "dataRows": {
    "source": "jsonPath",
    "value": "$.data.metrics.*"
  },
  "dataAdapters": {
    "items": [
      {
        "type": "flatten_values",
        "config": {
          "dataPath": "$.data.metrics.*",
          "valuesPath": "$.audience_activity.*"
        }
      }
    ]
  }
}

Below you can find example field definitions that read from the transformed structure:

[
  {
    "id": "date",
    "label": "Date",
    "dataType": "string.time.date",
    "value": {
      "source": "jsonPath",
      "value": "$.date"
    }
  },
  {
    "id": "audience_activity_hour",
    "label": "Audience activity hour",
    "dataType": "int.number.value",
    "value": {
      "source": "jsonPath",
      "value": "$.audience_activity_hour"
    }
  },
  {
    "id": "audience_activity_count",
    "label": "Audience activity count",
    "dataType": "int.number.value",
    "value": {
      "source": "jsonPath",
      "value": "$.audience_activity_count"
    }
  }
]

Note: The flatten_values produces multiple rows from a single parent item, meaning that every field from the parent – including any metrics – are copied onto each new row. Summing a parent-level metric across the result will multiply its value by the number of flattened rows. If you need both parent-level totals and child-level breakdowns, expose them through separate report types.