1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

add a test for unquoted values

This commit is contained in:
stleary 2017-02-26 11:09:41 -06:00
parent a66abf22a8
commit e41972a574

View file

@ -51,6 +51,23 @@ public class JSONObjectTest {
new JSONObject(myBean); new JSONObject(myBean);
} }
/**
* The JSON parser is permissive of unambiguous unquoted keys and values.
* Such JSON text should be allowed, even if it does not strictly conform
* to the spec. However, after being parsed, toString() should emit strictly
* conforming JSON text.
*/
@Test
public void unquotedText() {
String str = "{key1:value1, key2:42}";
JSONObject jsonObject = new JSONObject(str);
String textStr = jsonObject.toString();
assertTrue("expected key1", textStr.contains("\"key1\""));
assertTrue("expected value1", textStr.contains("\"value1\""));
assertTrue("expected key2", textStr.contains("\"key2\""));
assertTrue("expected 42", textStr.contains("42"));
}
/** /**
* A JSONObject can be created with no content * A JSONObject can be created with no content
*/ */