Parsing Json with list of dictionaries

Hi, I’m trying to parse a Json that contains a list of dictionaries and then, access the data.

From the Dynamo interface it is possible to access the list items, but from the Python interface, the list items are not accessible. See example below:

Any help will be appreciated


Edit: this issue is directly related to the Dictionary and List types (not Python native). If I replace the Dynamo node Data.ParseJSON with the following Python script,

import json
OUT = json.loads(IN[0])

everything works fine, both the Dynamo and Python accessors (because it returns dict and list)

Yup. It looks like ParseJSON returns an enumerable instead of a plain list.


You can convert the enumerable to a list directly if you don’t want to enumerate:
param_list = list(my_dict['param_list'])

Thanks for the explanation. I was working with a more complicated json structure and I was a little bit confused when accessing the items of the enumerable.

For my particular case, I find easier to do json.loads(s) instead of checking every list entry.

2 Likes

Iit seems that there is an inconsitency at the Dynamo node. The graphical output says List while the type is Enumerable.

From what I can see… Technically it isn’t a .net list, but a Dynamo one. This is a bit of a wrapper class which catches most .net collection objects when passed into the Dynamo environment so that base level nodes can process the item.