@@ -0,0 +1,45 @@
1+import java.io.ByteArrayInputStream;
2+import java.io.IOException;
3+import java.nio.file.Files;
4+import java.nio.file.Paths;
5+
6+import java.io.File;
7+import java.util.Map;
8+
9+import com.grack.nanojson.JsonParser;
10+
11+public class TestJSONParsing {
12+
13+ public static boolean isValidJSON(byte[] b) {
14+ try {
15+ Object o = JsonParser.any().from(new ByteArrayInputStream(b));
16+ if (new String(b).trim().equals("null"))
17+ return o == null;
18+ return o != null;
19+ } catch (Exception e) {
20+ System.out.println(e);
21+ return false;
22+ }
23+ }
24+
25+ public static void main(String[] args) {
26+
27+ if (args.length == 0) {
28+ System.out.println("Usage: java TestJSONParsing file.json");
29+ System.exit(2);
30+ }
31+
32+ try {
33+ byte[] b = Files.readAllBytes(Paths.get(args[0]));
34+ if(isValidJSON(b)) {
35+ System.out.println("valid");
36+ System.exit(0);
37+ }
38+ System.out.println("invalid");
39+ System.exit(1);
40+ } catch (IOException e) {
41+ System.out.println("not found");
42+ System.exit(2);
43+ }
44+ }
45+}