Http Get Request -> save Response as JSON array

Hi,

I am calling an external API in HTTP Get Request blueprint node. This API returns JSON as response. The API response returns an array of JSON objects when tested in browser. Now I want to take this result into Unreal into a JSON Array variable.

When I check result body in the HTTP Get Request blueprint node, it shows Wildcard Result as the return data type, then I am trying to map it into a Json object array (set as a variable). This is not happening and a message pops up saying “string is not compatible with JSON object structure”. When I map it to a string variable it works fine.

How do we get a http response saved to a JSON array using blueprints?

Here is the blueprint setup.
The node with breakpoint added, shows json string as a string value but json obect is always empty.

Sample JSON response received from the request.
[
{
“success”: true,
“item_id”: “Test Item 01 from API”,
“message”: “random message as required”
},
{
“success”: false,
“item_id”: “Number 902 received from API”,
“message”: “Item is not existing”
}
]

Thank you.


Khalid

LoadJsonFromString cannot read an array. You should parse it manually:

I don’t know why your example has the wrong characters, but I changed them:
image

However, this approach will work with simple arrays only. If an entering string contains nested objects or arrays, it won’t work.

My Products

1 Like

Thank you for the response.

Wrong characters might be copy paste issue into this reply editor. It comes as valid double quotes from api endpoint to unreal node.

I will try your solution now and get back in few minutes.

Hi supremative

Your solution worked for me.

And regarding your comment “this approach will work with simple arrays only. If an entering string contains nested objects or arrays, it won’t work”,
This one is for a simple demo/poc and we are using simple array of json objects. Later when we need to parse complex objects we will go for c++ based approach to handle the case of complex json.

Please let me know if there is any suggestion you would like to highlight.

Thank you for your timely input.

1 Like

Alternatively, you can wrap the array in an object while in string form :

// FString ResultBody = "[ {...}, {...}, {...} ]"
FString JsonObjectString = FString::Printf(TEXT("{\"array\":%s}"), *ResultBody);

Then parse it normally as a json object.

2 Likes

Good idea! It works:

1 Like