code: def _visit(lines):
      deque = collections.deque()
      root_level = 0
      dicc = {"expr": lines[root_level][1], "children": []}
      processed = set()
      for index in range(len(lines)):
          child_level, expr = lines[index]
          if child_level == root_level + 1:
              new_dicc = {"expr": expr, "children": []}
              if (
                  len(dicc["children"]) == 0
              ):  # No es necesario, deberia funcionar con solo append
                  dicc["children"] = [new_dicc]
              else:
                  dicc["children"].append(new_dicc)
              deque.append((index, child_level, expr, new_dicc))
              processed.add(index)
  
      for index in processed:
          lines[index][0] = -1
  
      while len(deque) > 0:
          curr_index, curr_level, curr_expr, curr_dicc = deque.pop()
          processed = set()
  
          if curr_index < len(lines) - 1:  # is brother
              child_level, expr = lines[curr_index + 1]
              if child_level == curr_level:
                  continue
              elif child_level == curr_level + 1:
                  index = curr_index + 1
                  if _is_double_children(curr_expr):
                      while (
                          index < len(lines)
                          and len(curr_dicc["children"]) < 2
                      ):
                          child_level, expr = lines[index]
                          if child_level == curr_level + 1:
                              new_dicc = {"expr": expr, "children": []}
                              if len(curr_dicc["children"]) == 0:
                                  curr_dicc["children"] = [new_dicc]
                              else:
                                  curr_dicc["children"].append(new_dicc)
                              processed.add(index)
                              deque.append(
                                  (index, child_level, expr, new_dicc)
                              )
                          index += 1
                  else:
                      while (
                          index < len(lines)
                          and len(curr_dicc["children"]) < 1
                      ):
                          child_level, expr = lines[index]
                          if child_level == curr_level + 1:
                              new_dicc = {"expr": expr, "children": []}
                              if len(curr_dicc["children"]) == 0:
                                  curr_dicc["children"] = [new_dicc]
                              else:
                                  curr_dicc["children"].append(new_dicc)
                              processed.add(index)
                              deque.append(
                                  (index, child_level, expr, new_dicc)
                              )
                          index += 1
  
          for index in processed:
              lines[index][0] = -1
      return json.dumps(dicc)
  
file_path: blazingsql/pyblazing/pyblazing/apiv2/algebra/json_plan.py
imports: import collections
  import json
  import re
label_desc: Use image node_id 5 for calling a global function with example usage: _visit(lines) and returns: json