bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

Jolt Transformer for Splitting a field value #1269

Closed abhiupa087 closed 2 months ago

abhiupa087 commented 2 months ago

Hi,

I am trying to write a Jolt Spec for transforming below Input JSON to a provided Output JSON. Input JSON { "headers": { "SourceXPath": "ds_id:db_name:table_name" }, "value": { "content": [ { "entityName": "column_name_1", "data": [ "425 442 4000", "206 442 4000" ] }, { "entityName": "column_name_2", "data": [ "jacknjill@hill.com", "jillnjack@hill.com" ] } ] } }

Desired Output JSON [ { "entityName": "column_name_1", "data": [ "425 442 4000", "206 442 4000" ], "parentXpath": [ "ds_id", "db_name", "table_name" ] }, { "entityName": "column_name_2", "data": [ "jacknjill@hill.com", "jillnjack@hill.com" ], "parentXpath": [ "ds_id", "db_name", "table_name" ] } ]

I wrote below JOLT Spec for this. [ { "operation": "shift", "spec": { "headers": { "SourceXPath": { "@(2,SourceXPath)": "parentXpath" } }, "value": { "content": { "*": { "entityName": "[&1].entityName", "data": "[&1].data", "@(1,parentXpath)": "[&1].parentXpath" } } } } }, { "operation": "modify-overwrite-beta", "spec": { "parentXpath": "=split(':', @(1,parentXpath))" } }, { "operation": "shift", "spec": { "*": { "parentXpath": "[&1].parentXpath", "entityName": "[&1].entityName", "data": "[&1].data" } } } ]

But it does not give me desired output, Can you please help and suggest what is wrong with this Jolt spec?

abhiupa087 commented 2 months ago

Does Jolt even support the split functionality?

abhiupa087 commented 2 months ago

Was able to solve this, Thanks.