Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/main/java/org/skyscreamer/jsonassert/JSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class JSONParser {
// "A number can be represented as integer, real, or floating point. JSON does not support octal or hex
// ... [or] NaN or Infinity".
private static final String NUMBER_REGEX = "-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?";
private static final String BOOLEAN_REGEX = "true|false";

private JSONParser() {}

Expand All @@ -41,10 +42,12 @@ public static Object parseJSON(final String s) {
if (s.trim().startsWith("{")) {
return new JSONObject(s);
}
else if (s.trim().startsWith("[")) {
if (s.trim().startsWith("[")) {
return new JSONArray(s);
} else if (s.trim().startsWith("\"")
|| s.trim().matches(NUMBER_REGEX)) {
}
if (s.trim().startsWith("\"")
|| s.trim().matches(NUMBER_REGEX)
|| s.trim().matches(BOOLEAN_REGEX)) {
return new JSONString() {
@Override
public String toJSONString() {
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public void testNumber() {
testFail("310.1e-1", "31.01", STRICT); // should fail though numbers are the same?
}

@Test
public void testBoolean() {
testPass("true", "true", STRICT);
testFail("true", "false", STRICT);
testPass("false", "false", STRICT);
testFail("false", "true", STRICT);
}

@Test
public void testSimple() {
testPass("{id:1}", "{id:1}", STRICT);
Expand Down