Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Jolt Spec to add a key-value pair to every object in a array

avatar
Contributor
{
    "responseMetadata": {
        "responseType": "PERSONAL",
        "activityDataExist": true
    },
    "serviceFunctionCode": "Send",
    "requestId": "1234",
    "responseCode": "SUCCESS",
    "responseData": {
        "responseList": [
            {
                "individualInfo": {
                    "firstName": "Jessica",
                    "middleName": "dean",
                    "lastName": "William",
                    "dateOfBirth": "07/18/1986"
                }
            }
        ]
    }
}
In the above Json I want to add "activityUID":"${UUID()}" as the first field in individualInfo object. 
Json may contain more than one IndividualInfo object.
Can you please help me with the Json spec to do that.
1 REPLY 1

avatar
Super Guru

Hi,

 

You can try the following spec:

 

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "responseData": {
        "responseList": {
          "*": {
            "individualInfo": {
              "#${UUID()}": "responseData.responseList.[&2].individualInfo.activityUID",
              "firstName": "responseData.responseList.[&2].individualInfo.&",
              "middleName": "responseData.responseList.[&2].individualInfo.&",
              "lastName": "responseData.responseList.[&2].individualInfo.&",
              "dateOfBirth": "responseData.responseList.[&2].individualInfo.&"
            }
          }
        }
      }
    }
  }
]

 

If that helps please accept solution.

Thanks