Nested Json lists in Iron Python

Hi all,

I am having trouble with reading nested json lists. I used the following code:

import rhinoscriptsyntax as rs
import json
import ghpythonlib.components as ghcomp
import ghpythonlib.treehelpers as gt

attr = json.loads(parameters)

#extraxt parameters
D1 = attr["D1"]
test = gt.list_to_tree(D1)

#different approach
H2 = json.dumps(attr)
H3 = H2[1]

The inputted Json input contains two nested json lists, but when I look at what “test” outputs the two lists are put together. How can I get this this attribute data sorted as it was inputted (in two seperated data trees). So in this case that would mean 6 branches.

json_python.gh (7.2 KB)

You are inputting two JSON strings (with the GHPython component thus running the implicit cycles). Here’s running one JSON string:


json_python_01.gh (10.8 KB)

Edit: Here’s operating on a list of JSON strings, which seems closer to what you’re looking for:


json_python_02.gh (4.3 KB)

1 Like

Thanks a lot @AndersDeleuran!
That was just what I am was looking for.

1 Like

Hi @AndersDeleuran,

If I want to slpit the tree, like with the gh SplitTree component How can I make this work in Python.
Somehow I do not manage with invoking the grasshopper function in python.

I’d suggest doing the splitting on the Python list (i.e. using its native functionality) before converting it to a DataTree. Mixing paradigms like this usually gets quite messy/verbose!