code: def get_android_hierarchy(d):
      
      page_xml = d.dump_hierarchy(compressed=False, pretty=False).encode('utf-8')
      dom = xml.dom.minidom.parseString(page_xml)
      root = dom.documentElement
  
      def travel(node):
          # print(node)
          if node.attributes is None:
              return
          json_node = parse_uiautomator_node(node)
          json_node['id'] = str(uuid.uuid4())
          if node.childNodes:
              children = []
              for n in node.childNodes:
                  sub_hierarchy = travel(n)
                  if sub_hierarchy:
                      children.append(sub_hierarchy)
              json_node['children'] = children
          return json_node
  
      return travel(root)
docs: Returns:
          JSON object