private static void toJson(MetricsPacket metric, JsonGenerator generator, boolean addStatus) throws IOException {
        generator.writeStartObject();
        if (addStatus) {
            generator.writeNumberField("status_code", metric.statusCode());
        }
        if ( ! Instant.EPOCH.equals(metric.timestamp())) {
            generator.writeNumberField("timestamp", metric.timestamp().getEpochSecond());
        }
        generator.writeStringField("application", metric.service().id);

        if ( ! metric.metrics().isEmpty()) {
            generator.writeObjectFieldStart("metrics");
            for (var m : metric.metrics().entrySet()) {
                generator.writeFieldName(m.getKey().id);
                JacksonUtil.writeDouble(generator, m.getValue().doubleValue());
            }
            generator.writeEndObject();
        }

        if ( ! metric.dimensions().isEmpty()) {
            generator.writeObjectFieldStart("dimensions");
            for (var m : metric.dimensions().entrySet()) {
                generator.writeStringField(m.getKey().id, m.getValue());
            }
            generator.writeEndObject();
        }
        Set<ConsumerId> routing = extractSetForRouting(metric.consumers());
        if (!routing.isEmpty()) {
            generator.writeObjectFieldStart("routing");
            generator.writeObjectFieldStart(YAMAS_ROUTING);
            generator.writeArrayFieldStart("namespaces");
            for (ConsumerId consumer : routing) {
                generator.writeString(consumer.id);
            }
            generator.writeEndArray();
            generator.writeEndObject();
            generator.writeEndObject();
        }
        if (addStatus) {
            generator.writeStringField("status_msg", metric.statusMessage());
        }
        generator.writeEndObject();
    }
Converts the given json formatted string to a list of metrics packet builders.
Note that this method returns an empty list if an IOException occurs,
and logs a warning as a side effect.
metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/model/json/YamasJsonUtil.java