Support Questions

Find answers, ask questions, and share your expertise

Stuck with this JOLT Tranformation

avatar
Contributor

Hi Community,

hope someone can help me to build this transform:

 

My Input:

{
"Orders": [{
"Headers": {
"UniqShipment": "0"
},
"Goods": [{
"GoodsTypeID": 3,
"GoodsTypeName": "ALTRI MOBILI LEGNO",
"GoodsDetails": [{
"Packs": 1

}, {
"Packs": 1
}, {
"Packs": 1
}]
}],
"References": [{
"TypeReference": "DT",
"ValueReference": "006611",
"DateReference": "2023-04-14"
}, {
"TypeReference": "CM",
"ValueReference": "JOHN"
}, {
"TypeReference": "OC",
"ValueReference": "V1250-0010"
}, {
"TypeReference": "RG",
"ValueReference": "TRCA_CATR726240_CA_006611_14_04_2023.json"
}]

}]
}

My Desired Output:

{
	"header": {
		"UniqShipment": "0"
	},
	"rows": {
		"GoodsTypeName": ["ALTRI MOBILI LEGNO", "ALTRI MOBILI LEGNO", "ALTRI MOBILI LEGNO"],
		"Packs": [1, 1, 1],
		"ValueReference": ["V1250-0010", "V1250-0010", "V1250-0010"]
	}
}

My Transformation so far:

[
  {
    "operation": "shift",
    "spec": {
      "Orders": {
        "*": {
          "Headers": "header",
          "Goods": {
            "*": {
              "GoodsDetails": {
                "*": {
                  "@(2,GoodsTypeName)": "rows.GoodsTypeName",
                  "Packs": "rows.Packs"
                }
              }
            }
          }
        }
      }
    }
  }
]

Which Produce the following result:

{
  "header" : {
    "UniqShipment" : "0"
  },
  "rows" : {
    "GoodsTypeName" : [ "ALTRI MOBILI LEGNO", "ALTRI MOBILI LEGNO", "ALTRI MOBILI LEGNO" ],
    "Packs" : [ 1, 1, 1 ]
  }

 Now i need to make the last part:

Based on the value of TypeReference which has to be "OC" then add the list of ValueReference per each element of "rows array" like this:

 

{
	"header": {
		"UniqShipment": "0"
	},
	"rows": {
		"GoodsTypeName": ["ALTRI MOBILI LEGNO", "ALTRI MOBILI LEGNO", "ALTRI MOBILI LEGNO"],
		"Packs": [1, 1, 1],
		"TypeReference": ["V1250-0010", "V1250-0010", "V1250-0010"]
	}
}

 

Many Thanks for your help, appreciate!

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi,

I think you can achieve this in two shift transformation as follows:

 

 

[
  {
    // 1st transformation is basically to isolate 
    // "OC" value reference into Orders.ValueReference
    "operation": "shift",
    "spec": {
      "Orders": {
        "*": {
          "Headers": "Orders[#2].&",
          "Goods": "Orders[#2].&",
          "References": {
            "*": {
              "TypeReference": {
                "OC": {
                  "@(2,ValueReference)": "Orders[#2].ValueReference"
                }
              }
            }
          }
        }
      }
    }
  },
  //2ed Transformation is the same as you had except for
  //fetching the isolated ValueReference above
  //into its own Array based on the GoodsDetails array
  {
    "operation": "shift",
    "spec": {
      "Orders": {
        "*": {
          "Headers": "header",
          "Goods": {
            "*": {
              "GoodsDetails": {
                "*": {
                  "@(2,GoodsTypeName)": "rows.GoodsTypeName",
                  "Packs": "rows.Packs",
                  "@(4,ValueReference)": "rows.ValueReference"
                }
              }
            }
          }
        }
      }
    }
  }

]

 

 

If the helps please accept solution.

Thanks

View solution in original post

1 REPLY 1

avatar
Super Guru

Hi,

I think you can achieve this in two shift transformation as follows:

 

 

[
  {
    // 1st transformation is basically to isolate 
    // "OC" value reference into Orders.ValueReference
    "operation": "shift",
    "spec": {
      "Orders": {
        "*": {
          "Headers": "Orders[#2].&",
          "Goods": "Orders[#2].&",
          "References": {
            "*": {
              "TypeReference": {
                "OC": {
                  "@(2,ValueReference)": "Orders[#2].ValueReference"
                }
              }
            }
          }
        }
      }
    }
  },
  //2ed Transformation is the same as you had except for
  //fetching the isolated ValueReference above
  //into its own Array based on the GoodsDetails array
  {
    "operation": "shift",
    "spec": {
      "Orders": {
        "*": {
          "Headers": "header",
          "Goods": {
            "*": {
              "GoodsDetails": {
                "*": {
                  "@(2,GoodsTypeName)": "rows.GoodsTypeName",
                  "Packs": "rows.Packs",
                  "@(4,ValueReference)": "rows.ValueReference"
                }
              }
            }
          }
        }
      }
    }
  }

]

 

 

If the helps please accept solution.

Thanks