private void writeNewline() throws IOException {
    out.write("\n");
    for (int i = 0; i < indentLevel; i++) {
      out.write(indent);
    }
  }
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