Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jolt Transformer Grouping based on the fields inside the object

I wanted to group the input array objects based on the fields profileName, assetLevel1, and assetLevel2.

Input:

{
  "product": [
    {
      "id": "id1",
      "entity": "entity1",
      "productID": "productID1",
      "productName": "productName1",
      "unitPrice": "unitPrice1",
      "assetLevel1": "Equities",
      "assetLevel2": "US Large Cap Equity",
      "profileName": "Beginner Level"
    },
    {
      "id": "id3",
      "entity": "entity3",
      "productID": "productID3",
      "productName": "productName3",
      "unitPrice": "unitPrice3",
      "assetLevel1": "Fixed Income",
      "assetLevel2": "Global Aggregate Funds",
      "profileName": "Novice Level"
    },
    {
      "id": "id2",
      "entity": "entity2",
      "productID": "productID2",
      "productName": "productName2",
      "unitPrice": "unitPrice2",
      "assetLevel1": "Equities",
      "assetLevel2": "US Large Cap Equity",
      "profileName": "Beginner Level"
    }
  ]
}

My current spec:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
  {
    "operation": "shift",
    "spec": {
      "product": {
        "*": "@profileName.@assetLevel1[]"
      }
    }
  }
]

Desired output:

{
  "Beginner Level": {
    "Equities": [
      {
        "US Large Cap Equity": [
          {
            "assetLevel1": "Equities",
            "assetLevel2": "US Large Cap Equity",
            "entity": "entity1",
            "id": "id1",
            "productID": "productID1",
            "productName": "productName1",
            "profileName": "Beginner Level",
            "unitPrice": "unitPrice1"
          },
          {
            "assetLevel1": "Equities",
            "assetLevel2": "US Large Cap Equity",
            "entity": "entity2",
            "id": "id2",
            "productID": "productID2",
            "productName": "productName2",
            "profileName": "Beginner Level",
            "unitPrice": "unitPrice2"
          }
        ]
      }
    ]
  },
  "Novice Level": {
    "Fixed Income": [
      {
        "Global Aggregate Funds": [
          {
            "assetLevel1": "Fixed Income",
            "assetLevel2": "Global Aggregate Funds",
            "entity": "entity3",
            "id": "id3",
            "productID": "productID3",
            "productName": "productName3",
            "profileName": "Novice Level",
            "unitPrice": "unitPrice3"
          }
        ]
      }
    ]
  }
}

Can anyone help?

I have tried the above but unable to proceed as I am a newbie in this.

>Solution :

You can use this spec:

[
  {
    "operation": "shift",
    "spec": {
      "product": {
        "*": "@profileName.@assetLevel1.@assetLevel2[]"
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": "MANY"
      }
    }
  }
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading