API json document data structure is confusing

I don’t know how to phrase this the computer science way. It might be a dumb question - I’ve never worked with json or SQL or mongo…just grad school math and physics. But, did the developers invent the data structure themselves, or is this a somewhat standard practice?

Normally when I think of any heirarchal nested list or tree, I think of an n-dimensional sparse array, where n is the deepest # of levels with data. 7 levels deep can be represented by a 7-dimensional array. Most of the arrays fields are empty, in other words sparse. But I also know >2 dimensions is a more common way of thinking in the math field than the computer science & databases field, which likes 1 or 2 dimensional arrays. It looks like this json is essentially a 2 dimensional array, in other words, it could be an Excel spreadsheet with the array “nodes” as the rows, and the various fields as columns. And then one of the columns is the list of children nodes. And then, some javascript or database must reconstruct the nested list from those child node ID lists? I know, this probably doesn’t interest many people…

TL;DR I feel like, without the script to reconstruct the nested list, getting the json document from the API is useless because it’s flat. That, or this is a normal programmer/json data structure and I just need to be directed to some article about it. TL;DRTL;DR: im stuck lol

It appears to be more a relational database organization. Very convenient if you just want to do “for all nodes, if text is … then do something with that node.” Then you don’t have to worry about the hierarchy. Kind of inconvenient if you want to worry about the hierarchy. It’s also helpful in dealing with links. If node A has a link to B, it’s easy to find B, because it’s just look in nodes for B.

what you’re looking for would be code something like this (completely untested).

function get_json_text(document, node)
  text = node.content
text += " : { "
  for each child in node.children
       text += get_json_text(document, child)
text += " }"

Likely you don’t want to make text in this fashion. You instead would want to make a new json object following the same program structure, of the type you want.

Or, just use a thing like this:

function get_children(document, node)
    children = { }
    for each child in node.children
          for each dnode in document.nodes
                if dnode.id == child.id) 
1 Like