Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Create lists and objects regrouping with JoltTransformJSON

avatar
Contributor

Hello
I have created a JSON body but I need to reconstruct it so I can send it in a REST API.

Input :

 

{
  "systemId" : "4",
  "systemName" : "Main",
  "items.nid" : "123",
  "items.birth_date" : "1978-01-01",
  "items.last_name" : "Willson",
  "items.nationality" : "GN",
  "formId": 1
}

 

 

Output :

 

{
  "formId": 1,
  "systemId" : "4",
  "systemName" : "Main",
  "items" {
    "nid" : "123",
    "birth_date" : "1978-01-01",
    "last_name" : "Willson",
    "nationality" : "GN"
  }
}

 

 

I used JoltTransformJSON but with no luck always get null as a result, I can't figure how to regroup them based on the name "items.*" . how can I regroup my items or is there a better way to solve this point ?

1 ACCEPTED SOLUTION

avatar
Contributor

I used this Jolt Spec with the help of chatGPT
and it worked
[{
"operation": "shift",
"spec": {
"systemId": "systemId",
"systemName": "systemName",
"items.nid": "items.nid",
"items.birth_date": "items.birth_date",
"items.last_name": "items.last_name",
"items.entity_type": "items.entity_type",
"items.citizenship": "items.citizenship",
"items.nationality": "items.nationality",
"items.business_name": "items.business_name",
"items.customer_type": "items.customer_type",
"items.first_name": "items.first_name"
}
}, {
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": "=ifEmpty(@(1,&),'')"
}
}
}, {
"operation": "shift",
"spec": {
"systemId": "systemId",
"systemName": "systemName",
"items": "items"
}
}]

View solution in original post

1 REPLY 1

avatar
Contributor

I used this Jolt Spec with the help of chatGPT
and it worked
[{
"operation": "shift",
"spec": {
"systemId": "systemId",
"systemName": "systemName",
"items.nid": "items.nid",
"items.birth_date": "items.birth_date",
"items.last_name": "items.last_name",
"items.entity_type": "items.entity_type",
"items.citizenship": "items.citizenship",
"items.nationality": "items.nationality",
"items.business_name": "items.business_name",
"items.customer_type": "items.customer_type",
"items.first_name": "items.first_name"
}
}, {
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": "=ifEmpty(@(1,&),'')"
}
}
}, {
"operation": "shift",
"spec": {
"systemId": "systemId",
"systemName": "systemName",
"items": "items"
}
}]