I am currently working with data in JSON format and am attempting to convert it into a Python dictionary using a Python Script Node in KNIME. However, I seem to have encountered an issue, and the error message I’m receiving is as follows:
TypeError: the JSON object must be str, bytes, or bytearray, not Series.
I suspect that I might be missing a step or making an error somewhere in the process. Could someone please guide me on how to read JSON data into a Python Script Node and convert it into a Python dictionary?
Any assistance or insights would be greatly appreciated.
In your code line 5 you are trying to import a JSON to pd.DataFrame object.
I would suggest to use an intermediate ‘JSON to Table’ node; aiming to import a KNIME df into the ‘Python Script’ node.
Then you can use the following code:
import json
import knime.scripting.io as knio
import pandas as pd
# data in
df_knimedf = knio.input_tables[0].to_pandas()
df_dictionary = df_knimedf.to_dict()
print(type(df_dictionary))
Console:
INFO:numexpr.utils:NumExpr defaulting to 8 threads.
<class 'dict'>