public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator)
            throws JSONException {
        Object expected = JSONParser.parseJSON(expectedStr);
        Object actual = JSONParser.parseJSON(actualStr);
        if ((expected instanceof JSONObject) && (actual instanceof JSONObject)) {
            return compareJSON((JSONObject) expected, (JSONObject) actual, comparator);
        }
        else if ((expected instanceof JSONArray) && (actual instanceof JSONArray)) {
            return compareJSON((JSONArray)expected, (JSONArray)actual, comparator);
        }
        else if (expected instanceof JSONString && actual instanceof JSONString) {
            return compareJson((JSONString) expected, (JSONString) actual);
        }
        else if (expected instanceof JSONObject) {
            return new JSONCompareResult().fail("", expected, actual);
        }
        else {
            return new JSONCompareResult().fail("", expected, actual);
        }
    }
public static JSONCompareResult compareJSON ( String expectedStr , String actualStr , JSONComparator comparator ) throws JSONException { Object expected = JSONParser . parseJSON ( expectedStr ) ; Object actual = JSONParser . parseJSON ( actualStr ) ; if ( ( expected instanceof JSONObject ) && ( actual instanceof JSONObject ) ) { return compareJSON ( ( JSONObject ) expected , ( JSONObject ) actual , comparator ) ; } else if ( ( expected instanceof JSONArray ) && ( actual instanceof JSONArray ) ) { return compareJSON ( ( JSONArray ) expected , ( JSONArray ) actual , comparator ) ; } else if ( expected instanceof JSONString && actual instanceof JSONString ) { return compareJson ( ( JSONString ) expected , ( JSONString ) actual ) ; } else if ( expected instanceof JSONObject ) { return new JSONCompareResult ( ) . fail ( "" , expected , actual ) ; } else { return new JSONCompareResult ( ) . fail ( "" , expected , actual ) ; } }
Compares JSON string provided to the expected JSON string using provided comparator, and returns the results of
the comparison.
@param expectedStr Expected JSON string
@param actualStr JSON string to compare
@param comparator Comparator to use
@return result of the comparison
@throws JSONException JSON parsing error
@throws IllegalArgumentException when type of expectedStr doesn't match the type of actualStr