summaryrefslogtreecommitdiff
path: root/test_json_validity.py
blob: 026b02c5f819d6612fe624b6d41e7157368bf8db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)