Using newest record from JSON API response to HTTP Request

I am using an HTTP Request to call an API.

The response has multiple records returned in JSON format.
I need to use data associated with the highest RecordId number…

I have used Deserialize JSON in the past and can call out a specific JSON Path when I knew the correct response number [0],[1], etc. but this time I don’t know the order the records will come.

Below is a (simplified) JSON response with two sample records.

In the sample I need the following two values
(because the recordId for the first record[0] is highest in the sample.)

 3520729   from   .ResponseData.Records[0].RecordId 
 12   from     .ResponseData.Records[0].RecordImage 

The real data can contain MANY records in the response, not just two like the sample, and in no particular order.

How do I go about getting these two values?

{
“ResponseData”: {
“Records”: [
{
“CurrentRecord”: “200679600”,
“RecordId”: 3520729,
“RecordImage”: 12
},
{
“CurrentRecord”: “200679600”,
“RecordId”: 2403386,
“RecordImage”: 6
}
]
}
}

Thanks in advance to this super helpful community!

@Mike_Campbell

I hope this is what you are looking for

jobj("ResponseData")("Records").OrderBy(function(x) x("RecordId")).Last()("RecordImage")

cheers

1 Like

Anil, YES - and I can’t thank you enough!

I made a mocked up test with just this code (screenshot) and it worked FLAWLESSLY. (I did have to add .toString, but the error I was getting made that clear enough)

That is EXACTLY what I needed, and I can see using this and similar code in many places in my future.

![This image shows a UiPath workflow sequence that reads a JSON file, deserializes the JSON content, assigns the maximum RecordId value to a variable, and displays the result in a message box.

Blessings to you for the year!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.