private void writeIterable(Iterable iterable) throws IOException {
    out.write("[");
    if (prettyPrint) {
      ++indentLevel;
      writeNewline();
    }
    Iterator iterator = iterable.iterator();
    if (iterator.hasNext()) {
      while(true) {
        write(iterator.next());
        if (!iterator.hasNext()) break;
        out.write(",");
        if (prettyPrint) {
          writeNewline();
        }
      }
    }
    if (prettyPrint) {
      --indentLevel;
      writeNewline();
    }
    out.write("]");
  }
Note: The {@link #writeString} and {@link #hex} methods
are based on code from class {@code StringEscapeUtils} in Commons Lang 2.6.
spock-core/src/main/java/org/spockframework/util/JsonWriter.java