How to get specific values from a REST API JSON response?

Hi automators,

I am using my ERP’s API to fetch some JSON data.

I am using the UiPath.Web.Activities.HttpClient and putting the “Response Content” in a string variable.

bild

The write line gives this output (simplified)

{
	"order": {
		"messageId": "b7d49ef8-ec34-4b1f-a4ab-01eb9e34ba1b",
		"messageCreationTime": "2024-05-19T21:25:10.835+0200",
		"contact": {
			"oid": 5069334,
			"version": 1,
			"manualName": false,
			"manualPhone": false,
			"manualEmail": false,
			"manualDepartment": false
		},
		"pickupEarliest": null,
		"pickupLatest": null,
		"transferringEarliest": null,
		"transferringLatest": null,
		"deliveryEarliest": null,
		"deliveryLatest": null,
		"equipmentAccessibleFrom": null,
		"responseLatest": null,
		"plannedStartTime": "2024-05-17T00:00:00.000+0200",
		"plannedStopTime": "2024-05-17T00:00:00.000+0200"
}
}

Let’s say I wanted to get the value of order → messageId.

In for example python I’d to print(ALY_CONTENT_RESPONSE.JSON()[“order”][“messageId”]) - how can I achieve something similar?

I’ve of course Googled a lot and I’ve tried deserialize JSON into a Dictionary<String,String> variable:

bild
bild
bild

And then tried API_RESPONSE_JSON(“order”)(“messageId”).ToString which seems to be what a lot of people are doing, but I can’t get passed this error;

What am I doing wrong?

Assumption: Project is set to VB.Net

grafik
Deserialize it into a JOBject - myJObject

And access:
grafik

Damn sorry, I knew I forgot something. No the project is set to C#.

Tried redoing the project in VB.NET but on the Deserialize JSON I’m getting this error;

Deserialize JSON: Unexpected character encountered while parsing value: {. Path ‘’, line 1, position 1.

But the JSON response is definitely valid.

As we shared the immediate panel screenshot we have validated the working solution:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

we doubt. show us the variable value from immediate panel. Ensure that not the shared JSON text file is used and that there is no " at the start.

Also you can check with https://jsonlint.com/

It’s most definitely correct JSON. We’ve built hundreds of API calls using PHP / Python and various inhouse systems using the ERP Response.

Here’s the entire response (582 lines) from a Python request with the same format as UiPath sends it pasted into jsonlint;

Here’s me printing the JSON variabler string with “Write Line” in UiPath that I then try to deserialize;

Hence - The JSON is valid.

as mentioned:

AND

we have seen the working statement.

When:

Then try again as mentioned:
Deserialize JSON activity | TypeArgument: JObject

That works fine - thank a lot.

But I’m not sure why. I’m not giving it an jObject, it’s getting a string variable which is what the HTTP request is returning?

Perfect, so the topic can be closed

http request returns the JSON string
this we parsed into a JObject

Oh OK, so type argument refers to the output? Not the input?

Yes, it will define into which type it should be parsed

Ok then I understand what went wrong, I interpreted that as the output type.

Thanks for your patience and help.

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