Skip to content

Commit e41972a

Browse files
committed
add a test for unquoted values
1 parent a66abf2 commit e41972a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/org/json/junit/JSONObjectTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ public void jsonObjectByNullBean() {
5151
new JSONObject(myBean);
5252
}
5353

54+
/**
55+
* The JSON parser is permissive of unambiguous unquoted keys and values.
56+
* Such JSON text should be allowed, even if it does not strictly conform
57+
* to the spec. However, after being parsed, toString() should emit strictly
58+
* conforming JSON text.
59+
*/
60+
@Test
61+
public void unquotedText() {
62+
String str = "{key1:value1, key2:42}";
63+
JSONObject jsonObject = new JSONObject(str);
64+
String textStr = jsonObject.toString();
65+
assertTrue("expected key1", textStr.contains("\"key1\""));
66+
assertTrue("expected value1", textStr.contains("\"value1\""));
67+
assertTrue("expected key2", textStr.contains("\"key2\""));
68+
assertTrue("expected 42", textStr.contains("42"));
69+
}
70+
5471
/**
5572
* A JSONObject can be created with no content
5673
*/

0 commit comments

Comments
 (0)