public void writeVariant(Variant var) throws IOException {
        if (var.isStringType()) {
            writeString(var.getString());

        } else if (var.isObjectType()) {
            out.append('{');
            writeln();
            boolean first = true;
            for (Map.Entry<String, Variant> e : var.varObject().entrySet()) {
                if (first) {
                    first = false;
                } else {
                    out.append(',');
                    writeln();
                }
                writeString(e.getKey());
                out.append(':');
                writeVariant(e.getValue());
            }
            out.append('}');

        } else if (var.isArrayType()) {
            out.append('[');
            boolean first = true;
            for (Variant item : var.varList()) {
                if (first) {
                    first = false;
                } else {
                    out.append(',');
                    writeln();
                }
                writeVariant(item);
            }
            out.append(']');

        } else if (var.isPrimaryType()) {
            out.append(var.toString());

        } else if (var.isNull()) {
            out.append("null");

        } else {
            throw new RuntimeException("Ignoring unsupported var: " + var.getDebugInfo());
        }
    }