code: public String format(String json) {
          String result = null;
          if (json != null){
              if (json.startsWith("{")) {
                  result = new JSONObject(json).toString(4);
              } else if (json.startsWith("[")) {
                  JSONObject jsonObject = new JSONObject("{'a': " + json + "}");
                  org.json.JSONArray array = (org.json.JSONArray) jsonObject.get("a");
                  result = array.toString(4);
              }
          }
          return result;
      }
docs: Creates formatted version of the supplied JSON.
  @param json JSON to format.
  @return formatted version.