Forum Discussion

DirkZ70's avatar
DirkZ70
New Contributor
10 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

 

 

  • Attached is a pipeline to do this mapping. It looks like this:

    First Mapper:

    Second Mapper:

    Hope that helps!

     

     

2 Replies

  • Attached is a pipeline to do this mapping. It looks like this:

    First Mapper:

    Second Mapper:

    Hope that helps!

     

     

  • DirkZ70's avatar
    DirkZ70
    New Contributor

    Perfect,
    you are a genius 👍
    Your example do exactly what i needed.

    Many thanks,
    Dirk