def dump_headers(json_dict, hlir, keep_pragmas=False):
    headers = []
    id_ = 0
    for name, p4_header_instance in hlir.p4_header_instances.items():
        if p4_header_instance.virtual:
            continue
        header_instance_dict = OrderedDict()
        header_instance_dict["name"] = name
        header_instance_dict["id"] = id_
        id_ += 1
        header_instance_dict["header_type"] =\
            p4_header_instance.header_type.name
        header_instance_dict["metadata"] = p4_header_instance.metadata

        if keep_pragmas:
            add_pragmas(header_instance_dict, p4_header_instance)

        for p4_field in p4_header_instance.fields:
            if p4_field.default is not None and p4_field.default != 0:
                LOG_CRITICAL(
                    "In file '{}' at line {}: "
                    "non-zero metadata initialization is not supported by this "
                    "backend; field '{}' cannot be initialized to {}".format(
                        p4_header_instance.filename, p4_header_instance.lineno,
                        str(p4_field), p4_field.default))

        headers.append(header_instance_dict)

    json_dict["headers"] = headers