JSON Handling

Working with Json from Blueprints

Some of these features are only available in V27 onwards

To work with HTTP / WebSockets effectively, you'll often need to manipulate JSON data from Blueprint.

To facilitate this, we have enabled Epic's JsonBlueprintUtilities plugin which offers a collection of nodes for manipulating Json Objects. In addition, we have provided an extended set of nodes to augment the out of the box features that Epic provide.

JSON Blueprint Utilities

Epic's JsonBlueprintUtilities plugin offers several useful features:

To / From String

Load Json From String

This can take a JSON string and convert it to a JSON Object

Get Json String

Converts a JSON Object to a JSON string

Convert Struct to Json String

Converts a UStruct directly to a JSON string

Get / Set Fields

The Get Field node allows you to retrieve a specific field from a JSON Object. The return value is a wildcard and so requires explicitly casting or connecting to an input pin.

The Set Field node allows you to set a specific field on a JSON Object with a wildcard typed field.

Internally this relies on Unreal's Json Serializer, so if a wildcard type is not explicitly serializable to/from Json you may end up with unexpected failures or results.

Field Inspection

Has Field

Allows you to inspect if a Json Object has a specific field.

Get Field Names

allows you to list all the field names on an object; which can then be used to enumerate them in a loop.

M2 JSON Utilities

We have augmented Epic's nodes with some of our own to further facilitate working with JSON data.

To / From UStruct

Make Json Object from Struct

Converts any UStruct to a JSON object.

Make Struct from Json Object

Converts a JSON object into a struct of a specific, known type

Read Json Object into struct

Uses an existing struct (eg: in a variable) to read a JSON object

Nested Objects

Get Json Object at Location

Allows you to specifiy a dot.delimited.path to a field containing a JSON object.

For example; given this JSON object

{
    "person": {
        "forename": "alice",
        "surname": "smith"
    },
    "contact": {
        "address": {
            "street": "park avenue",
            "town": "exampleville"
        }
    }
}

The path of contact.address would return a Json Object containing:

{
    "street": "park avenue",
    "town": "exampleville"
}

To Map

This node allows you to read all fields into a specified (pre-made) map of either strings or integers.

JSON Value Handling

These features are only available in V28 onwards

In V28 we have added a range of improvements that allow working with JSON at a deeper level than Objects. These are exposed as a set of JSON Value functions.

JSON Values

There are a series of functions available to create the main JSON Value primiities of Null, Number, String, Array and Object.

Each of these creates a JSON Value that wraps the provided data. You can extract this data from a JSON Value by using the Get Json Value XXX functions, which will return the wrapped data if the type matches.

The Is Json Value XXX functions can be used to test if a JSON Value is the type you want.

Additionally the functions Get Json Value Type and Is Json Value Type are available to query based on the type.

As you would expect; there are a couple of To/From JSON String helpers available.

The Value to Json String function can only work on JSON Values that wrap Arrays or Objects; this is due to a limitation in the built-in Unreal JSON Serializer.

JSON Arrays

There are several ways to create a JSON Array. If you have an array of homogeneous types (eg: all String or all Number, etc) then the Create Json Value XX Array functions will help you.

If you have a heterogeneous list of value types, then the Create Json Value Array function will be best for you. This allows you to add any JSON Value type to an array.

You can also create an Array by using the Json String to Value function, using a Json representation of the array.

In order to access the content of the JSON Array you have a couple of options at present.

Get Json Value Array Items will give you access to an array of the content; essentially unwrapping the array for you to use. You can then iterate on the contents as you would any normal array.

Individual items can be accessed by using the Get Json Array Item Count and Get Json Array Item functions. These return the length of the array and the item at a specific location.

JSON Objects

JSON Objects can be wrapped in JSON Values. In addition to the JSON Object functionality discussed elsewhere, the JSON Value library gives you the ablity to Get or Set fields from an object using the Get Json Object Field Value and Set Json Object Field Value functions.

You can also use the Get Json Value at Location to access a specific value in a JSON Object hierarchy.

For example; given this JSON object

{
    "person": {
        "forename": "alice",
        "surname": "smith"
    },
    "contact": {
        "address": {
            "street": "park avenue",
            "town": "exampleville"
        }
    }
}

The path of contact.address.street would return a JSON Value of type String that contains the string value park avenue. This is useful for accessing individual fields from a nested hierarchy.

Last updated