def dump_meters(json_dict, hlir, keep_pragmas=False):
    meters = []
    id_ = 0
    for name, p4_meter in hlir.p4_meters.items():
        meter_dict = OrderedDict()
        meter_dict["name"] = name
        meter_dict["id"] = id_
        id_ += 1
        if p4_meter.binding and (p4_meter.binding[0] == p4.P4_DIRECT):
            meter_dict["is_direct"] = True
            meter_dict["binding"] = p4_meter.binding[1].name
            meter_dict["size"] = p4_meter.binding[1].max_size
            meter_dict["result_target"] = format_field_ref(p4_meter.result)
        else:
            meter_dict["is_direct"] = False
            meter_dict["size"] = p4_meter.instance_count
        meter_dict["rate_count"] = 2  # 2 rate, 3 colors
        if p4_meter.type == p4.P4_COUNTER_BYTES:
            type_ = "bytes"
        elif p4_meter.type == p4.P4_COUNTER_PACKETS:
            type_ = "packets"
        else:  # pragma: no cover
            LOG_CRITICAL("invalid meter type")
        meter_dict["type"] = type_

        if keep_pragmas:
            add_pragmas(meter_dict, p4_meter)

        meters.append(meter_dict)

    json_dict["meter_arrays"] = meters