gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [PATCH 5/5] Add script to test for JSON validity


From: chris
Subject: [gpsd-dev] [PATCH 5/5] Add script to test for JSON validity
Date: Tue, 5 Jun 2012 17:26:24 +0100

From: Christian Gagneraud <address@hidden>

This simple script can be used to check if the JSON cade presented on its
standard input is valid JSON.
It has already been very useful to chase up typos in gpsd_json.c

Signed-off-by: Christian Gagneraud <address@hidden>
---
 test_json_validity.py |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100755 test_json_validity.py

diff --git a/test_json_validity.py b/test_json_validity.py
new file mode 100755
index 0000000..026b02c
--- /dev/null
+++ b/test_json_validity.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+#
+# Christian Gagneraud - 2012
+# Simple python script that will parse json dictionaries on it's input,
+# If it fails, it will print the offending line and an error message.
+# The goal is to check that GPSD outputs valid JSON.
+#
+
+import json, sys
+
+success = True
+lc = 0
+for line in sys.stdin.readlines():
+    lc += 1
+    try:
+        # Load the json dictionary, it should raise an error if it is malformed
+        item = json.loads(line)
+    except Exception as e:
+        success = False
+        print "%d: %s" % (lc, line.strip()) 
+        print "%d: %s" % (lc, e) 
+
+exit(0 if success else 1)
-- 
1.7.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]