Forum Discussion

ddangler's avatar
ddangler
New Contributor III
8 years ago

How to flatten hierarchial JSON structure?

Hi Forum,

I have hierarchical JSON structure coming as input and need to flatten(and transformation) the document as output. Below is the simple example showing input and output structure. I tried doing this with Mapper, Strcuture and JSON Splitter snaps but could not achieve it. Anyone know how to solve this?

Input document structure:

[
  {
    "entity": {
      "results": [
        {
          "id": 453721,
          "custom_fields": [
            {
              "id": 11111,
              "value": "AAAA"
            },
            {
              "id": 22222,
              "value": "BBBB"
            },
            {
              "id": 33333,
              "value": "CCCC"
            }
          ]
        }
      ]
    }
  }
]

Desired Output Document structure:

[
  {
    "entity": {
      "results": [
        {
          "id": 453721,
          "11111" : "AAAA",
          "22222" : "BBBB"
        }
      ]
    }
  }
]