Support Questions

Find answers, ask questions, and share your expertise

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"
}
}]