You are here:

JSON (JavaScript Object Notation) is a lightweight data-interchange format that is used widely across various computer applications. Lightact allows you to parse incoming JSON data stream into different Lightact variables, as well as package Lightact variables into a JSON string. An example of a simple JSON object with 3 variables would be:

{ “name”:”John”, “age”:30, “car”:null }

As you can see, each variable is written with a Key and a Value. For example, under the key name, there is a value John.

Parsing JSON String

A node that parses JSON in Lightact is called JSON Parser node.

json parser node

JSON input expects a properly formatted JSON string. Depending on what type of variable you want to read from the incoming JSON you should click the corresponding button on the node. For example, if you want to read a string value from the JSON string, you should click on Add string button. This will add another string input labeled Key, and another string output labeled Value.

json parser string

The layout above extracts the value of a variable written under the key: name. If we use the JSON string written at the beginning of this page as a JSON input, the string value is John.

json parser integer

In a similar way, you can extract integers or floats from.

Packaging Variables into JSON String

What if we wanted to package Lightact variables into a JSON string? In this case, we’d use JSON Packager node.

JSON packager node

With this node, we can package most types of Lightact variables. For example, the layout below packages a float, a string and a vec3 into a JSON string.

json packaging

The resulting JSON is:

{“float”: 12.00,”string”: “testString”,”vec3″: “1.000000;2.000000;3.000000”}

As you can see, vec3 (and vec2 as a matter of fact) get converted into a string where the components are delimited with a semi-colon.


Previous Text processing
Next Custom Shaders