diff options
author | Christian Gagneraud <cgagneraud@techworks.ie> | 2012-06-04 01:09:38 +0100 |
---|---|---|
committer | Christian Gagneraud <chris@techworks.ie> | 2012-06-20 10:05:40 +0100 |
commit | a307361e9942df5be76c1498007c296f6ea5b1fd (patch) | |
tree | 137fdeda1f0c3743ce39aa4ad920317c2687fb88 /test_json_validity.py | |
parent | e4974575fdd9fe5c04f765eecb19a119fd55e3ec (diff) | |
download | gpsd-a307361e9942df5be76c1498007c296f6ea5b1fd.tar.gz |
Add script to test for JSON validity
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
Diffstat (limited to 'test_json_validity.py')
-rwxr-xr-x | test_json_validity.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test_json_validity.py b/test_json_validity.py new file mode 100755 index 00000000..026b02c5 --- /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) |