private Inspector maybeConvertWset(Inspector data) {
            var wset = new Value.ObjectValue();
            for (int i = 0; i < data.entryCount(); i++) {
                Inspector obj = data.entry(i);
                if (obj.type() != Type.OBJECT || obj.fieldCount() != 2) {
                    return null;
                }
                Inspector item = obj.field("item");
                Inspector weight = obj.field("weight");
                if (! item.valid()) return null;
                if (! weight.valid()) return null;
                // TODO support non-integer weights?
                if (weight.type() != Type.LONG) return null;
                if (item.type() == Type.STRING) {
                    wset.put(item.asString(), weight.asLong());
                } else if (settings.jsonWsetsAll) {
                    wset.put(WithBase64.toJsonString(item, settings.enableRawAsBase64).toString(), weight.asLong());
                } else {
                    return null;
                }
            }
            return wset;
        }
Call after all fields in a hit to close the "fields" field of the JSON object
container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java