Forum Discussion

DirkZ70's avatar
DirkZ70
New Contributor
11 months ago
Solved

Convert array with objects into object with key/value pairs

Hello all,
i try to convert the following input/source into the described target structure with a mapper snap but i am not able to find a solution for this. Can anybody give me a hint or example how i can solve this problem 

My current source:

[
  {
    "recordset": {
      "item_id": "test_1",
      "classification": {
        "@class_id": "AB123",
        "attributes": [
          {
            "@name": "key_1",
            "$": "value_1"
          },
          {
            "@name": "key_2",
            "$": "value_2"
          },
          {
            "@name": "key_3",
            "$": "value_3"
          }
        ]
      }
    }
  },
  {
    "recordset": {
      "item_id": "test_2",
      "classification": {
        "@class_id": "AB456",
        "attributes": [
          {
            "@name": "key_4",
            "$": "value_4"
          },
          {
            "@name": "key_5",
            "$": "value_5"
          },
          {
            "@name": "key_6",
            "$": "value_6"
          },
          {
            "@name": "key_7",
            "$": "value_7"
          }
        ]
      }
    }
  }
]

The target which i expect should look like the following:

[
  {
    "recordset": {
      "item": "test_1",
      "classification": {
        "class_id": "AB123",
        "attributes": {
          "key_1": "value_1",
          "key_2": "value_2",
          "key_3": "value_3"
        }
      }
    }
  },
  {
    "recordset": {
      "item": "test_2",
      "classification": {
        "class_id": "AB456",
        "attributes": {
          "key_4": "value_4",
          "key_5": "value_5",
          "key_6": "value_6",
          "key_7": "value_7"
        }
      }
    }
  }
]

Many thanks in advance,

Dirk