code: private static void prettyPrint(JsonReader reader, JsonWriter writer) throws IOException {
          writer.setIndent("  ");
          while (true) {
              final JsonToken token = reader.peek();
              switch (token) {
                  case BEGIN_ARRAY:
                      reader.beginArray();
                      writer.beginArray();
                      break;
                  case END_ARRAY:
                      reader.endArray();
                      writer.endArray();
                      break;
                  case BEGIN_OBJECT:
                      reader.beginObject();
                      writer.beginObject();
                      break;
                  case END_OBJECT:
                      reader.endObject();
                      writer.endObject();
                      break;
                  case NAME:
                      final String name = reader.nextName();
                      writer.name(name);
                      break;
                  case STRING:
                      final String s = reader.nextString();
                      writer.value(s);
                      break;
                  case NUMBER:
                      final String n = reader.nextString();
                      writer.value(new BigDecimal(n));
                      break;
                  case BOOLEAN:
                      final boolean b = reader.nextBoolean();
                      writer.value(b);
                      break;
                  case NULL:
                      reader.nextNull();
                      writer.nullValue();
                      break;
                  case END_DOCUMENT:
                      return;
                  default:
                      LOGGER.debug("Unexpected JSON toekn {}", token.toString());
                      break;
              }
          }
      }
docs: Streams from a json reader to a json writer and performs pretty printing.
  
  This function is copied from https://sites.google.com/site/gson/streaming
  
  @param reader json reader
  @param writer json writer
  @throws IOException thrown if the json is malformed