bazaarvoice / jolt

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

Replace a map based on value #794

Open yarabsyp opened 5 years ago

yarabsyp commented 5 years ago

Input

{ "addressInfo": { "legalAddress": { "country": "US", "attentionLinePrefix": "ATTN", "attentionLineDetail": "detail", "line1": "testmail@test.com", "line2": "One Pershing Plz", "line3": "Jersey City", "city": "New Jersey", "stateProvince": "AK" }, "sameAsLegalAddress": [ "Y" ], "mailingAddress": { "country": "AL", "attentionLinePrefix": "sdc", "attentionLineDetail": "fd", "line1": "", "line2": "", "line3": "", "city": "", "stateProvince": "" }, "additionalAddress": [] } }

if sameAsLegalAddress is Y then copy the legalAddress to mailingAddress..

outPut : { "addressInfo": { "legalAddress": { "country": "US", "attentionLinePrefix": "ATTN", "attentionLineDetail": "detail", "line1": "testmail@test.com", "line2": "One Pershing Plz", "line3": "Jersey City", "city": "New Jersey", "stateProvince": "AK" }, "sameAsLegalAddress": [ "Y" ], "mailingAddress": { "country": "US", "attentionLinePrefix": "ATTN", "attentionLineDetail": "detail", "line1": "testmail@test.com", "line2": "One Pershing Plz", "line3": "Jersey City", "city": "New Jersey", "stateProvince": "AK" }, "additionalAddress": [] } }

what we tried here we using this spec

[ { "operation": "shift", "spec": { "addressInfo": { "sameAsLegalAddress": { "": "&2.legalAddress.&1" }, "": "&1.&" } } }, { "operation": "shift", "spec": { "addressInfo": { "legalAddress": { "sameAsLegalAddress": { "Y": { "@2": ["&4.legalAddress", "&4.mailingAddress"] }, "": { "@2": "&4.&3" } } }, "*": "&1.&" } } }

]

getting result is below .. plz help us to resovle this issue

{ "addressInfo" : { "legalAddress" : { "aType" : "2", "country" : "US", "attentionLinePrefix" : "ATTN", "attentionLineDetail" : "detail", "line1" : "testmail@test.com", "line2" : "One Pershing Plz", "line3" : "Jersey City", "city" : "New Jersey", "stateProvince" : "AK", "sameAsLegalAddress" : "Y" }, "mailingAddress" : [ { "aType" : "2", "country" : "US", "attentionLinePrefix" : "ATTN", "attentionLineDetail" : "detail", "line1" : "testmail@test.com", "line2" : "One Pershing Plz", "line3" : "Jersey City", "city" : "New Jersey", "stateProvince" : "AK", "sameAsLegalAddress" : "Y" }, { "aType" : "Y", "country" : "AL", "attentionLinePrefix" : "sdc", "attentionLineDetail" : "fd", "line1" : "", "line2" : "", "line3" : "", "city" : "", "stateProvince" : "" } ], "additionalAddress" : [ ] } } @milosimpson

BobbySingla commented 5 years ago

Jolt Spec file as your output required files:

spec.txt

Is it Okay?