0

I am new to jolt transformation. what would be the jolt spec to transform my source json

{
  "version": "123",
  "payload": {
    "details": {
      "payload_json": "{\"FName\":\"rishi\",\"LName\":\"dx\",\"Id\":\"ABC123\",\"aadharId\":\"XYZ22\"}"
    }
  }
}

to target JSON

{
  "firstName": "rishi",
  "lastName": "dx",
  "id": "ABC123",
  "officialIds": [
    {
      "type": "aadhar",
      "value": "XYZ22"
    }
  ]
}

I tried using Google Gemini and Micosoft Copilot to get the jolt spec, but neither of them are generating correct spec.

1
  • I think the suggested option would be better and more direct than handling it by using jolt for this current case. Commented Jul 9 at 22:01

1 Answer 1

1

You can solve this easily using JSLT:

let json_payload = from-json(.payload.details.payload_json)
    
{
  "firstName": $json_payload.FName ,
  "lastName":  $json_payload.LName ,
  "id":  $json_payload.Id,
  "officialIds":[for ($json_payload) {"type":.key,"value":.value } if(not(contains(.key,["FName","LName","Id"])))]  
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.