static S jsonEncode_breakAtLevel1(O o) { new StringBuilder buf; jsonEncode_breakAtLevel1(o, buf, 1); ret str(buf); } static void jsonEncode_breakAtLevel1(O o, StringBuilder buf, int level) { if (o == null) buf.append("null"); else if (o instanceof S) buf.append(quote((S) o)); else if (o instanceof Number || o instanceof Bool) buf.append(o); else if (o instanceof Map) { Map map = cast o; buf.append("{"); bool first = true; for (O key : keys(map)) { if (first) first = false; else buf.append(","); if (level == 1) buf.append("\n "); buf.append(quote((S) key)); buf.append(":"); jsonEncode_breakAtLevel1(map.get(key), buf, level+1); } if (level == 1) buf.append("\n"); buf.append("}"); } else if (o instanceof Collection) { Collection l = cast o; buf.append("["); bool first = true; for (O element : l) { if (first) first = false; else buf.append(","); if (level == 1) buf.append("\n "); jsonEncode_breakAtLevel1(element, buf, level+1); } if (level == 1) buf.append("\n"); buf.append("]"); } else fail("Unknown object for JSON encoding: " + className(o)); }