bugGPSD - Bugs: bug #39051, ais.py : json output has bad...

 
 

bug #39051: ais.py : json output has bad formating for strings

Submitted by:  Jerome <jjl>
Submitted on:  Thu May 23 09:39:38 2013  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon Jul 1 10:49:02 2013, comment #1:

Fixed in git, thanks for the bug report.

Eric S. Raymond <esr>
Project Administrator
Thu May 23 09:39:38 2013, 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

Jerome <jjl>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #28146:  ais_json_string.patch added by jjl (1kB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by esr (Posted a comment)
  • -unavailable- added by jjl (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri Nov 22 13:45:55 2013esrOpen/ClosedOpen=>Closed
    Mon Jul 1 10:49:02 2013esrStatusNone=>Fixed
    Thu May 23 09:39:38 2013jjlAttached File-=>Added ais_json_string.patch, #28146

    Back to the top


    Powered by Savane 3.1-cleanup1