JSON.dump array with different types including nested arrays type error

Hi,

I am trying to save input as a .json, but for some reason json.dump cant handle nested arrays?

IN[1] is the data im saving as a json array, below the python script the preview is shown thats the loaded json file.

When i add a nested list as a value this breaks and it doesnt save the data correctly:

As far as i can tell a nested array should be a valid type, or am i mistaken?

Have you tried using the StringifyJSON node from Dynamo instead?

That works, but I would like to be able to just supply a list to the python node instead of having to use a stringify.json node beforehand

If i turn this into a custom node however i could just use the stringify json node in there… That works :slight_smile:

Out of curiosity i do wonder why i can’t just do json.dump similar to JSON.stringify in javascript…

You can, but you’re missing a few bits of memory serves, and I am not at a PC to test (2 week holiday). You can try googling the error as this type of Python function is not unique to Dynamo you’re apt to get a solution via stack exchange, geeks for geeks, or stack overflow post. You can also look into the code in the zip posted below as I recall that does a bunch with the JSON module.

1 Like

It’s json.dumps(data) :man_facepalming:

Thank you Jacob!

1 Like