def json_nodes(nodes):
  nodes_info = []

  for node in nodes:
    info = dict(path=node.path, is_leaf=node.is_leaf)
    if node.is_leaf:
      info['intervals'] = [{'start': i.start, 'end': i.end} for i in node.intervals]

    nodes_info.append(info)

  return sorted(nodes_info, key=lambda item: item['path'])