skip to Main Content

Hi I’am trying a jolt transform of below

{
  "Others": {
    "eventTime": "2024-09-05T01:50:05.861",
    "groupArticleNumber": "IW6012",
    "groupModelNumber": "JSO42",
    "seasonCode": "20242"
  },
  "x": [
    {
      "materialComposition": "100% PET-REC",
      "mainMaterialFlag": true
    }
  ],
  "y": [
    {
      "sourcingSizeCode3": "550"
    },
    {
      "sourcingSizeCode3": "540"
    }
  ]
}

and the expected output as

[
  {
    "eventTime": "2024-09-05T01:50:05.861",
    "groupArticleNumber": "IW6012",
    "groupModelNumber": "JSO42",
    "seasonCode": "20242",
    "materialComposition": "100% PET-REC",
    "mainMaterialFlag": true,
    "sourcingSizeCode3": "550"
  },
  {
    "eventTime": "2024-09-05T01:50:05.861",
    "groupArticleNumber": "IW6012",
    "groupModelNumber": "JSO42",
    "seasonCode": "20242",
    "materialComposition": "100% PET-REC",
    "mainMaterialFlag": true,
    "sourcingSizeCode3": "540"
  }
]

I need a jolt spec for same. I have tried so many spec trying multplexing aslo but no luck.

2

Answers


  1. Hi hope this spec helps you resolve your query.

    [
      {
        "operation": "shift",
        "spec": {
          "y": {
            "*": {
              "sourcingSizeCode3": "[#2].sourcingSizeCode3",
              "@(2,Others)": {
                "*": "[#3].&"
              },
              "@(2,x)": {
                "*": {
                  "*": "[#4].&"
                }
              }
            }
          }
        }
      }
    ]
    

    enter image description here

    Login or Signup to reply.
  2. It’s kind of an extension of this former question " #75451057 " :

    Loop through the array of objects with highest numbe of objects, namely "y" while transferring whole content of "Others" object and "x" array inside such as

    [
      {
        "operation": "shift",
        "spec": {
          "y": {
            "*": {
              "@2,Others": { "*": "[&1].&" }, // go two levels up the tree to grab the values of the "Others" object
              "@2,x": { "*": { "*": "[&2].&" } },// walk through all deepest elements of "x" array
              "*": "[&1].&" //get all key-value pairs within the objects under the "y" array
            }
          }
        }
      }
    ]
    

    OR

    [
      {
        "operation": "shift",
        "spec": {
          "y": {
            "*": {
              "@2,Others|@2,x[0]": {//directly pass content for the zeroth index of the x array
                "*": "[&1].&"
              } , 
              "*": "[&1].&" //get all key-value pairs within the objects under the "y" array
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search