@Test public void testWhitespaceEquivalence() { String[][] cases = { { "-0", " -0" }, { "-1", "-1\t" }, { "2", "2\n" }, { "3", "\t 3\r\r" }, { "4.555", " 4.555 " }, { "6.7e-76", "\n6.7e-76\t" }, { "null", " null \n" }, { "false", "false " }, { "true", " true" }, { "6.7e-76", "\n6.7e-76\t" }, { "[]", "[ ]" }, { "[null]", "[ null ] " }, { "[8,9]", "[ 8, 9 ]" }, { "{}", "\t{\n\r}\t\t" }, { "[{}]", " [ { }] " }, { "[[[]],[],[],{}]", "[[[ ]], [] ,[],{} ]" }, { "{\"a\":{}}", "{ \"a\" : {}}" }, { "{\"bb\":[],\"c\":0}", "{ \"bb\" : [ ] , \"c\" :0 }" }, { "{\"d\":false,\"\\b\":[true]}", " {\"d\" :false ,\"\\b\": [ true] } " }, }; for (String[] cs : cases) assertJsonEquals(Json.parse(cs[0]), Json.parse(cs[1])); }
public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; }
Json { public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; } }
Json { public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; } private  Json(); }
Json { public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; } private  Json(); static String serialize(Object obj); static Object parse(String str); static Object parseFromFile(File file); static Object parseFromFile(File file, Charset cs); static Object parseFromUrl(URL url); static Object parseFromUrl(URL url, Charset cs); static void serializeToFile(Object obj, File file); static void serializeToFile(Object obj, File file, Charset cs); @SuppressWarnings("unchecked") static Object getObject(Object root, Object... path); static boolean getBoolean(Object root, Object... path); static int getInt(Object root, Object... path); static long getLong(Object root, Object... path); static float getFloat(Object root, Object... path); static double getDouble(Object root, Object... path); static String getString(Object root, Object... path); @SuppressWarnings("unchecked") static List<Object> getList(Object root, Object... path); @SuppressWarnings("unchecked") static Map<String, Object> getMap(Object root, Object... path); }
Json { public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; } private  Json(); static String serialize(Object obj); static Object parse(String str); static Object parseFromFile(File file); static Object parseFromFile(File file, Charset cs); static Object parseFromUrl(URL url); static Object parseFromUrl(URL url, Charset cs); static void serializeToFile(Object obj, File file); static void serializeToFile(Object obj, File file, Charset cs); @SuppressWarnings("unchecked") static Object getObject(Object root, Object... path); static boolean getBoolean(Object root, Object... path); static int getInt(Object root, Object... path); static long getLong(Object root, Object... path); static float getFloat(Object root, Object... path); static double getDouble(Object root, Object... path); static String getString(Object root, Object... path); @SuppressWarnings("unchecked") static List<Object> getList(Object root, Object... path); @SuppressWarnings("unchecked") static Map<String, Object> getMap(Object root, Object... path);  }