Python Script node. How to work with output table?

@Maya

Thanks for the additional information. If you want to bring the response into KNIME as a JSON object then you can convert the dictionary to a JSON string and return that as a cell in the KNIME table as follows. Note, you will need to import json and pandas as pd. I’ve included a dummy dictionary to demonstrate the workflow. Note: If you have the response as a JSON you do not need to convert it to a dictionary, you could just return it in the dataframe by changing json_string to response.

import json
import knime.scripting.io as knio
import pandas as pd

response = { 
  "one": 1, 
  "two": 2, 
  "three": 3
}

json_string = json.dumps(response)

df = pd.DataFrame([{"json": json_string}])

knio.output_tables[0] = knio.Table.from_pandas(df)

Once you have exported the json string you can convert it to a json object using the string to json node. The script and nodes are in the attached workflow.
JSON.knwf (7.3 KB)

DiaAzul
LinkedIn | Medium | GitHub

3 Likes