@Override
  public String format(String json) {
    String formattedString = null;
    if (json == null || json.trim().length() == 0) {
      Platform.get().warn("JSON empty.");
      return "";
    }
    try {
      if (json.startsWith("{")) {
        JSONObject jsonObject = new JSONObject(json);
        formattedString = jsonObject.toString(JSON_INDENT);
      } else if (json.startsWith("[")) {
        JSONArray jsonArray = new JSONArray(json);
        formattedString = jsonArray.toString(JSON_INDENT);
      } else {
        Platform.get().warn("JSON should start with { or [");
        return json;
      }
    } catch (Exception e) {
      Platform.get().warn(e.getMessage());
      return json;
    }
    return formattedString;
  }
Simply format the JSON using {@link JSONObject} and {@link JSONArray}.
xlog/src/main/java/com/elvishew/xlog/formatter/message/json/DefaultJsonFormatter.java