simplejson/simplejson — Issue #23: json decoder question
Author: alexkreimer
Created: 2011-11-16 09:47:55+00:00
State: open

How can I handle such a case with simplejson?

import simplejson
s = '[{"type":"image","width":100,"height":100,"x":63,"y":169,"src":"http://localhost:8000/media/images/anna.jpg","transform":""},{"type":"image","width":100,"height":100,"x":336,"y":163,"src":"http://localhost:8000/media/images/anna1.jpg","transform":""},{"type":"text","font":"10px \"Arial\"","font-size":20,"stroke":"none","fill":"#000","x":204,"y":90,"text":"default text","text-anchor":"middle"}]'
simplejson.loads(s)

---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
/home/alexk/prj/94x54/ in ()
----> 1 simplejson.loads(s)

/home/alexk/.virtualenvs/94x54/local/lib/python2.7/site-packages/simplejson/__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, **kw)
411 parse_constant is None and object_pairs_hook is None
412 and not use_decimal and not kw):
--> 413 return _default_decoder.decode(s)
414 if cls is None:
415 cls = JSONDecoder

/home/alexk/.virtualenvs/94x54/local/lib/python2.7/site-packages/simplejson/decoder.pyc in decode(self, s, _w)
400
401 """
--> 402 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
403 end = _w(s, end).end()
404 if end != len(s):

/home/alexk/.virtualenvs/94x54/local/lib/python2.7/site-packages/simplejson/decoder.pyc in raw_decode(self, s, idx)
416 """
417 try:
--> 418 obj, end = self.scan_once(s, idx)
419 except StopIteration:
420 raise JSONDecodeError("No JSON object could be decoded", s, idx)

JSONDecodeError: Expecting , delimiter: line 1 column 296 (char 296)