JSON to SDF

I’m trying to use the JSON Reader and the Python script node to convert a JSON file to sdf. I am using the script below in the Python script node:

import json

Load the JSON data from the input port

input_data = inputs[0].get_data()
json_data = json.loads(input_data[0][0])

Extract the relevant information from the JSON data

sdf_data = “Header\n\n”
for item in json_data:
sdf_data += “Item {\n”
sdf_data += " name: " + item[“name”] + “\n”
sdf_data += " value: " + item[“value”] + “\n”
sdf_data += “}\n”

Write the SDF data to the output port

outputs[0].set_data([[sdf_data]])

And I get the following error:

Executing the Python script failed: Traceback (most recent call last):
File “”, line 4, in
NameError: name ‘inputs’ is not defined

Hi,

please refer to KNIME Python Integration Guide about the naming of input and output variables.
In case of using the legacy Python nodes, you can also have a look at the templates shown in the configuration dialog.

Best regards
Steffen

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.