def dump_extern_instances(json_dict, hlir):
    extern_instances = []
    id_ = 0
    for name, p4_extern_instance in hlir.p4_extern_instances.items():
        extern_instance_dict = OrderedDict()
        extern_instance_dict["name"] = name
        extern_instance_dict["id"] = id_
        extern_instance_dict["type"] = p4_extern_instance.extern_type.name

        id_ += 1

        attributes = []
        for attribute, attr in p4_extern_instance.attributes.items():
            attr_type = p4_extern_instance.extern_type.attributes[attribute].\
                        value_type.type_name
            if attr_type != "bit" and attr_type != "int":  # pragma: no cover
                LOG_CRITICAL(
                    "Attribute type '{}' not supported for the "
                    "extern type '{}'. Supported values are bit and int".
                    format(attr_type, p4_extern_instance.extern_type.name))
            attribute_dict = OrderedDict()
            attribute_dict["name"] = attribute
            attribute_dict["type"] = "hexstr"
            attribute_dict["value"] = hex(attr)

            attributes.append(attribute_dict)

        extern_instance_dict["attribute_values"] = attributes
        extern_instances.append(extern_instance_dict)

    json_dict["extern_instances"] = extern_instances