The main issue here is that the organization of our response is based on “predicate” children; while the user should iterate in terms of “entity” children.
So, Node 2, 3 and 4 are all “value” nodes. Those should become part of Node 1 itself, stored as a key-value map.
Then regarding Node 5, there’re 5 UIDs there: 23, 24, 25, 31, 101. So, Node 1 has 5 children, with the attribute “friend”.
Each of these 5 children again would have a key-value map with the contents of Node 6 within them.
So, the graph would look something like this:
