I’ve been battling with the Unreal and the following JSON for a few days now, it’s an array (“state”) which has 2 sub-arrays, each containing a few JSON Object.
Using the JSON Utilities plugins I’ve tried accessing the individuals JSON object, using “For Each Loop” nodes and others “Array” nodes, this thread really helped me get on the right path to solve this, but so far and with many different attempts, I either have no results, or only the first JSON Object of each sub-array.
I believe I should need 2 “For Each Loop” nodes to iterate through the Array, then each subarray. Right now I kind of understand why it’s not working, but I can’t find an alternative that works.
Any help would be really appreciated, thanks for reading.
Blueprint support for JSON is clunky af, it’s probably not possible. Only the JsonObject type is exposed and that’s not gonna be enough to handle this case. Array of arrays are not supported in blueprints.
You’re gonna need C++ in some way or another. Either make your own function or find a better JSON plugin.
hi,
like @Chatouille said, you better be off creating your own c++ json reader. the plugin that comes with ue5 is very, very basic… if you have an json object array it wont read the file or string, which you can do in the plugin… i also tried hours… sorry to say
I’m going to necro this old post because it’s still coming up in Google results, so is still relevant many years later.
JSON support in Blueprints seems to be pretty full-featured now in 5.3, at least in terms of reading from an arbitrary well-formed JSON payload.
If you’re using a web-based API to acquire your JSON data, you’ll take advantage of the relatively new HTTP Request Node (not the Proxy function). You must enable (for 5.3 anyway) the HTTPBlueprint plugin from Epic, which should be bundled (since at least 5.1).
You’ll use a LoadJSONFromString node to parse the actual data. Set a breakpoint and use the debugger to ensure that you’re getting what you expect here before going any further I guess.
The most important concept is to create all the STRUCTS you need to replicate (exactly) your JSON structure. Here are some pointers:
Start from the deepest nested structure and work your way out. This is because as you create some of those outer structures, you’ll want to set some of the values to other structures. They must already be created in order to do so. So look through your JSON Schema and determine the deepest nested structures and replicate them first in Unreal
Objects are Maps in Unreal. Specifically: JSON Objects that do not have predefined properties (ie: the keys are variable) get turned into String Maps. String Maps have keys that are strings but can still use a STRUCT as a value (see #1 above)
Don’t forget you can iterate through a Map via its Keys array.
You can easily have Arrays of Structs as a variable. It’s almost inevitable if you’re dealing with a big JSON payload that some of it will be an array. If it’s an array of scalar values, great, just choose that value type and set it to Array. But if the value is complex, it’s a STRUCT and you can choose that struct as the value type and then set it to an Array of that struct type.
And this is life-changing, once you are dealing with a struct, remember that you can right-click the Output pin and “Split Struct” which then gives you all the pins corresponding to all the properties of your struct! It’s incredibly powerful and gives you direct access to every part of your JSON data.