Reading JSON dictionary into Python Script

I have the parameters of a model I am running in a JSON file, which I read through the JSON Reader node like this:

I plug this node into a Python Script node, and I get successfully read:

I use “my_parameter_combinations = knio.input_tables[0].to_pandas()”, and when reading the JSON so that the rest of the model can read what I have defined in the JSON as model 1 or 2, like this:

json_object = json.loads(my_parameter_combinations[‘json’][0])

I get the error “TypeError: the JSON object must be str, bytes or bytearray, not dict”.

What can I do to solve this error? Is there a proper way to read JSON dictionaries into a Python Script in KNIME? I am using KNIME AP 4.7.0.

I appreciate any help you can provide.

@edwar_forero maybe you can take a look at these examples with several ways to store and retrieve dictionaries:


Hi edwar_forero,

the error says that my_parameter_combinations['json'][0] is a dict (Python dictionary).
The question is, what do you want? You used json.loads. This method returns a dict. You already have a dict. There is no need to transform it.
If you do not want a dict, but a String in JSON format, then you can transform the dict via
a = json.dumps(my_parameter_combinations['json'][0])

See the following link (or others) for reference:
5 Ways to Convert Dictionary to JSON in Python | FavTutor



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