bazaarvoice / jolt

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

Debugging Nested Map of Arrays Transformer #1143

Open dp0245 opened 2 years ago

dp0245 commented 2 years ago

input: { "primary": { "type": "/smartmoney/prequal/prequalApplication", "systemInfo": { "identifier": "55200b86-a25b-4f31-86e7-0778d3dc59a9-001", "version": 1648862824000 }, "domainAttributes": { "authId": "1234", "workflowId": "a6d18fa5" }, "/smartmoney/prequal/applicant": [ { "type": "/smartmoney/prequal/applicant", "domainAttributes": { "firstName": "John", "lastName": "Smith" }, "/smartmoney/prequal/employment": [ { "type": "/smartmoney/prequal/employment", "domainAttributes": { "employerName": "ABC Ketchup Co", "employmentStatus": "ACTIVE" } }, { "type": "/smartmoney/prequal/employment", "domainAttributes": { "employerName": "Uber", "employmentStatus": "ACTIVE" } } ] }, { "type": "/smartmoney/prequal/applicant", "domainAttributes": { "firstName": "Sally", "lastName": "Smith" } } ] } }

transformer: [{ "operation": "shift", "spec": { "primary": { "systemInfo": { "identifier": "id", "version": "version" }, "domainAttributes": { "authId": "auth_id", "workflowId": "workflow_id" }, "/smartmoney/prequal/applicant": { "": { "domainAttributes": { "firstName": "applicants.[&2].firstName", "lastName": "applicants.[&2].lastName" }, "/smartmoney/prequal/employment": { "": { "domainAttributes": { "employerName": "applicants.[&2].employment.[&4].employerName", "employmentStatus": "applicants.[&2].employment.[&4].employmentStatus" } } } } } } } }]

output: { "id" : "es-test-55200b86-a25b-4f31-86e7-0778d3dc59a9-001", "version" : 1648862824000, "auth_id" : "1234", "workflow_id" : "a6d18fa5", "applicants" : [ { "firstName" : "John", "lastName" : "Smith", "employment" : [ { "employerName" : "ABC Ketchup Co", "employmentStatus" : "ACTIVE" } ] }, { "employment" : [ { "employerName" : "Uber", "employmentStatus" : "ACTIVE" } ], "firstName" : "Sally", "lastName" : "Smith" } ] }

desired output: { "id": "es-test-55200b86-a25b-4f31-86e7-0778d3dc59a9-001", "version": 1648862824000, "auth_id": "1234", "workflow_id": "a6d18fa5", "applicants": [ { "firstName": "John", "lastName": "Smith", "employment": [ { "employerName": "ABC Ketchup Co", "employmentStatus": "ACTIVE" }, { "employerName": "Uber", "employmentStatus": "ACTIVE" } ] }, { "firstName": "Sally", "lastName": "Smith" } ] }

dp0245 commented 2 years ago

I found the answer: [{ "operation": "shift", "spec": { "primary": { "systemInfo": { "identifier": "id", "version": "version" }, "domainAttributes": { "authId": "auth_id", "workflowId": "workflow_id" }, "/smartmoney/prequal/applicant": { "": { "domainAttributes": { // debug which level you are in by printing the level "#test": "&1.&2", "firstName": "applicants.[&2].firstName", "lastName": "applicants.[&2].lastName" }, "/smartmoney/prequal/employment": { "": { "domainAttributes": { // debug which level you are in by printing the level "#test": "&1.&2.&3.&4", "employerName": "applicants.[&4].employment.[&2].employerName", "employmentStatus": "applicants.[&4].employment.[&2].employmentStatus" } } } } } } } }]