Houdini 17.5 Nodes TOP nodes

Json Input TOP node

Extracts data from JSON files and creates attributes

On this page

This node will read in JSON files and extract data that is specified by the user. The user can specify the name of the work item attribute in which the data will be placed as well as its type and list index.

TOP Attributes

json_arrayindex

integer

When performing the Array Retrieve operation, this will be set to the object’s index in the array from which it was retrieved, or to 0 if the retrieved value was not stored in an array.

obj_index

integer

When performing the Array Retrieve operation, this will be set to the index of the object. This is useful when performing queries that use the wildcard operator, as this attribute acts as an identifier of the object from which the information was retrieved.

query

string

When performing the Array Retrieve operation, this shows the query that was used to conduct the operation. If the wildcard operator was used in the query, the wildcard will be replaced with the resolved value.

field

string

When performing the Array Retrieve operation, this attribute is set to the field that was retrieved during the operation.

Parameters

Node

Work Item Generation

Whether this node generates static or dynamic work items. You should generally leave this set to "Automatic" unless you know the node’s work items can be computed statically, or that they need to be generated dynamically.

Dynamic

This node always creates dynamic work items: it waits until the upstream work items are known, and generates new work items from the upstream work items.

Static

This node always creates static work items: it creates the number of work items it thinks it needs based on the parameters (and any upstream static items) before the network runs.

Automatic

If the input is static (a static processor, or a partitioner with only static inputs, or a mapper), this node generates static work items, otherwise it generates dynamic work items.

Source

JSON File

The source of the JSON file

Upstream Result File

Uses the result file produced by the upstream work item as the path to the JSON file.

Custom File Path

JSON file specified by a custom filepath.

Result Data Tag

The data tag used to select the result from the upstream work item.

File Path

The path to the JSON file.

Operation

Operation

This specifies the retrieval operation that you want to perform.

Retrieve

This operation allows single data extractions to be performed on the JSON file. For example, it can be used to query a specific value in an object or a value at a certain index in a list. The Data Extractions multiparameter specifies the extractions that should be performed on the JSON.

Array Retrieve

This operation allows a specified field to be extracted from each index of a list within the JSON file.

Deserialize Work Item

This operation will deserialize a workitem from the given JSON file, the file should be formatted as a serialized work item file, such as that produced by Json Output.

On Query Failure

This parameter controls what happens when any part of the query fails. An example of a query failure would be using an index in the query that is larger than the size of the array that is being indexed.

If the node is set to Raise Error mode, the node will automatically fail the entire operation when a query fails.

If the node is set to Add Warning mode, the node will attach a warning but the node will finish cooking. If an Array Retrieve operation is being performed, the node will attmept to complete the other queries.

Add Warning mode is useful if the JSON file contains non-uniform data – for example, when an array of objects may or may not contain a specific sub-object.

Data Extractions

The parameters in this multiparameter are used to specify the data extractions that should be performed when using the Retrieve operation.

Query

This parameter is used to specify the path to the JSON object or value that you want to extract. It uses a hierarchical syntax separated by "/" characters to specify the path. If an list is within the hierarchy, a number can be used to specify the array index.

If we have the following JSON file:

{ "plants" : [ { "name" : "tree", "inMyGarden" : true, "height" : 5.5 }, { "name" : "sunflower", "inMyGarden": false, "height" : 3 } ] }

And we wanted to retrieve the height of the first plant, the query would be:

plants/0/height

If we wanted to retrieve the name of the second plant, the query would be:

plants/1/name

When performing the Array Retrieve operation, the query must point to a list in the JSON, with one exception described below.

The Array Retrieve operation can make use of the wildcard (*) operator in its queries. The wildcard will cause branching traversal of the JSON hierarchy, where each object at that level becomes a branch of the JSON traversal.

If we have the following JSON file:

{ "Houdini" : { "Contexts" : { "Sop" : { "mountain" : { "name" : "Mountain" }, "polybevel" : { "name" : "PolyBevel" } }, "Top" : { "jsoninput" : { "name" : "Json Input" }, "jsonoutput" : { "name" : "Json Output" } } } } }

And we wanted to go the names of all the nodes in this JSON file, we could perform the following query:

Houdini/Contexts/*/*

with the field parameter set to name.

This will create 4 separate work items, each containing a node name. Note that json_arrayindex will be set to 0 on each, because these objects are all independent and not part of the same array.

Field

This parameter is only used when the Array Retrieve operation is being performed. It is used to specify the property that should be retrieved from each array index in the list pointed to by the query.

If the array pointed to by the Query is filled with anonymous objects (such as an array of integers), this parameter can be set to the wildcard operator (*) which simply means that it will get everything in the array.

Attribute Name

This specifies the name of the work item attribute to store the extracted value in.

PDG Value Index

This specifies the index of the work item attribute’s list to store the extracted value in.

PDG Attribute Type

This specifies the type of the data. It can be a string, integer, or float.

Examples

example_top_jsoninput Example for Json Input TOP node

This example demonstrates how to use json input node to create workitems based on information contained in json files.

The following examples include this node.

example_top_jsoninput Example for Json Input TOP node

This example demonstrates how to use json input node to create workitems based on information contained in json files.

See also

TOP nodes