@Override
    public String format(String json) {
        String formattedString = null;
        if (json == null || json.trim().length() == 0) {
            throw new FormatException("JSON empty.");
        }
        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 {
                throw new FormatException("JSON should start with { or [, but found " + json);
            }
        } catch (Exception e) {
            throw new FormatException("Parse JSON error. JSON string:" + json, e);
        }
        return formattedString;
    }
Simply format the JSON using {@link JSONObject} and {@link JSONArray}.
android/android_framework/base/src/main/java/com/elvishew/xlog/formatter/message/json/DefaultJsonFormatter.java