Thu 23 May 2013 09:39:38 AM UTC, original submission:
Hi,
In json output, the string values should be double-quoted.
For example, see json grammar on json.org
So some interpreters cannot analyse the ais.py output.
To reproduce (with a type24 aivdm) :
---8<------------------------
$> python --version
Python 2.6.6
$> json=$(echo '!AIVDM,1,1,,A,H3P;Nbhd44r0TT0000000000000,0*64'| ./ais.py -j)
$> python -c "import sys,json;json.loads(sys.argv[1])" "$json"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.6/json/decoder.py", line 336, in raw_decode
obj, end = self._scanner.iterscan(s, **kw).next()
File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan
rval, next_pos = action(m, context)
File "/usr/lib64/python2.6/json/decoder.py", line 185, in JSONObject
raise ValueError(errmsg("Expecting object", s, end))
ValueError: Expecting object: line 1 column 64 (char 64)
---8<------------------------
The produced json :
{"msgtype":24,"repeat":0,"mmsi":235069099,"partno":0,"shipname":KAAN II}
the shipname KAAN II should be "KAAN II"
Attached is a small patch to correct this problem. Surely this is not the most elegant code, but it shows a possible resolution.
Regards
Jérôme
|