Does anyone how to write a JOLT Transform with this situation:
Input :
[
{
"id": "65cf06b62fadc0122dc30f29",
"code": "H34.23.9-240216-0003",
"applicant": {
"eformId": "60d990f88e6893001e5a7b42",
"userId": "6186433deee4513fe0d86efc",
"data": {
"birthday": "",
"address": "Thôn Kon Năng Treang",
"gender": 2,
"nation": {
"label": "Việt Nam",
"value": "5f39f4a95224cf235e134c5c"
},
"ghiChu": "",
"identityDate": "",
"noiDung": "",
"phoneNumber": "",
"province": {
"label": "Tỉnh Kon Tum",
"value": "5def47c5f47614018c000062"
},
"identityNumber": "062195002130",
"soBoHoSo": "1",
"organization": "Y Thảo",
"district": {
"label": "Huyện Đắk Hà",
"value": "5def47c5f47614018c001615"
},
"identityAgency": {},
"fullname": "Y Thảo",
"fax": "",
"village": {
"label": "Xã Đắk Ui",
"value": "5def47c5f47614018c123509"
},
"email": ""
}
}
},
{
"id": "65cf24e3f21075472fe549c7",
"code": "H34.6-240216-0032",
"nationCode": "G22.99-240216-030023-H34",
"applicant": {
"eformId": "624bb547cdb7f7ec092bee16",
"data": {
"fullname": "CÔNG TY CỔ PHẦN VIEON",
"province": {
"label": "Thành phố Hồ Chí Minh",
"value": "5def47c5f47614018c000079"
},
"district": {
"label": "Quận 3",
"value": "5def47c5f47614018c001770"
},
"village": {
"label": "Phường Võ Thị Sáu",
"value": "5def47c5f47614018c127139"
},
"phoneNumber": "02838241919",
"fax": "02838241919",
"mail": "[email protected]",
"taxCode": "0314415573",
"contact": "Hoàng Lê Huế An ",
"contactPhoneNumber": "0385792805",
"chonDoiTuong": 2,
"hinhThucNop": 2,
"ownerFullname": "CÔNG TY CỔ PHẦN VIEON",
"identityNumber": "0314415573",
"ownerIdentityNumber": "0314415573",
"isOwnerDossier": true
}
}
}
]
Expected output :
[
{
"id": "65cf06b62fadc0122dc30f29",
"eformId": "60d990f88e6893001e5a7b42",
"gender": 2,
"fullname": "Y Thảo",
"ownerFullname": "",
"province_label": "Tỉnh Kon Tum"
},
{
"id": "65cf24e3f21075472fe549c7",
"eformId": "624bb547cdb7f7ec092bee16",
"gender": null,
"fullname": "CÔNG TY CỔ PHẦN VIEON",
"ownerFullname": "CÔNG TY CỔ PHẦN VIEON",
"province_label": "Thành phố Hồ Chí Minh"
}
]
2
Answers
You should loop through all the objects within the array in a shift spec such as
and add a modify spec in order to add
ownerFullname
attributes, with null values, if they don’t exist for any objectBefore sharing the answer, I would like to remind you about publishing data from your application to the internet, I can see there are phone numbers, addresses, and emails from your users/customers on the JSON data. That might lead you to the unnecessary issue of data privacy.
Here is the way you can approach your decided JSON output: