简体   繁体   中英

How to flatten array of arrays in json using jsonata

I want to flatten an array of arrays in json data into array of objects. I am giving input and expected output. I am not familiar with some flattening functions in jsonata and that's where I need help.

Input:

[
  [
    {
      "date": "2022-09-22",
      "name": "modules/dynatrace",
      "count": 60
    },
    {
      "date": "2022-09-22",
      "name": "modules/dynatrace/monitors/http-monitors/basic",
      "count": 4
    }
    ],
    [
    {
      "date": "2022-09-22",
      "name": "modules/splunk/hec-token",
      "count": 14
    },
    {
      "date": "2022-09-22",
      "name": "modules/aws/lambda/logs_streaming_splunk",
      "count": 29
    }
    ]
]

Output:

[
    {
      "date": "2022-09-22",
      "name": "modules/dynatrace",
      "count": 60
    },
    {
      "date": "2022-09-22",
      "name": "modules/dynatrace/monitors/http-monitors/basic",
      "count": 4
    },
    {
      "date": "2022-09-22",
      "name": "modules/splunk/hec-token",
      "count": 14
    },
    {
      "date": "2022-09-22",
      "name": "modules/aws/lambda/logs_streaming_splunk",
      "count": 29
    }
]

I used below command as mention in the another ticket and it worked for me.|https://stackoverflow.com/questions/49570172/jsonata-query-to-flatten-array-of-arrays

$reduce($, $append) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM