Choosing a Python JSON Translator

Choosing a Python JSON Translator

This is a draft for comments. I already know it needs further work.

Among other things, I plan to move this off WordPress so that the data are more generally usable.

I noticed publication of python-cjson recently. I wondered whether the
claimed 10 to 200 times speed increase was real. It was reasonable to expect that a
“C” back end would make a difference. So, a few lines of code later, here
is a quick evaluation of the popular JSON translators for Python.

If you do not want to read all of this, here is the bottom line.
All of the translators evaluated here work OK. python-cjson is much faster,
but it is less tolerant of edge-case inputs than some. Fortunately, in python
you do not really have to choose. You have the option to send the offending
input to another, more tolerant, implementation when cjson throws an exception.
So, you can have fast JSON processing and still adhere to the mantra, “Be
liberal in what you accept, conservative in what you send.”

This evaluation borrows heavily from a comparison of php json libraries .

Modules Evaluated

In no particular order, here are the JSON translators for this evaluation. Disclosure notification: I am the author of the minjsons.

Package Version License url Cheese Shop Name
python-cjson 1.0.3 LGPL http://cheeseshop.python.org/pypi/python-cjson/1.0.3 python-cjson
demjson 1.1 LGPL http://deron.meranda.us/python/demjson/ demjson
simplejson 1.4 MIT http://undefined.org/python/#simplejson simplejson
json-py 3.4 LGPL http://sourceforge.net/projects/json-py/
minjson (old) 3.4 (dist with json-py) LGPL/ZPL http://sourceforge.net/projects/json-py/
minjson distributed with jsonserver BSD http://zif.hill-street.net/jsonserver/ soon to be zif.jsonserver.minjson in “zif”

Speed tests

Code for the testdata object for the speed tests follows.

testdata = []
data1 = [1,1.01,'hello world',True,None,-1,11.011,"~!@#$%^&*()_+|",False,None]
data2 = {}
for k in ['zero','one','two','three','four','five','six','seven','eight','nine']:
    data2[k] = data1
for k in range(10):
    testdata.append(data2)
    

Timings were done using timeit, the minimum time of five sets
of 100 repetitions encoding or decoding the testdata object. These are not
really benchmarks. These numbers only provide a general idea of the
relative speed of the tested implementations.

Raw Speed of JSON Encoding Implementations
python-cjson demjson simplejson json-py minjson (old) minjson
Actual time (seconds) 0.1 3.0 0.9 0.8 0.3 1.0
Normalized (cjson=1.0) 1.0 31.4 9.5 8.6 3.0 10.2

In the above table, cjson is approximately three to thirty times as fast
encoding objects to JSON as the pure-python translators.

Raw Speed of JSON Decoding Implementations
python-cjson demjson simplejson json-py minjson (old) minjson
Actual time (seconds) 0.1 5.0 2.2 5.1 11.9 5.2
Normalized (cjson=1.0) 1.0 86.3 38.5 88.9 206.9 90.9

In the above table, cjson is approximately 40 to 200 times as fast
decoding objects from JSON as the pure-python translators.

Decoding tests

Python-cjson is fast. What are the risks? How well does it
decode JSON? json-py and minjson have some legacy code in them from earlier definitions
and misunderstandings of JSON. In particular, c-style comments and
single-quoted strings are allowed to some degree by these implementations.
cjson and simplejson are less tolerant of these and some other edge cases
that may crop up in some user-created JSON. Again, borrowing heavily from
the php evaluation article, following is a table of outputs from the various
python JSON translators, given some edge-case inputs. All of the tested translators
are presumably strict on output, so only input edge cases are illustrated here.

Edge-case JSON Decoding Results
test # input (wp removed backslashes; look to the right to see what is going on.) python-cjson demjson simplejson json-py minjson (old) minjson
0
""
empty JSON description (‘can not decode value’, ”) No JSON object could be decoded Nothing to read: ” Syntax error. Could not read ”. Unacceptable JSON expression:
1
"1"
1 1 1 1 1 1
2
"true"
True True True True True True
3
"null"
None None None None None None
4
""hello""
hello hello hello hello hello hello
5
"not a value"
cannot parse JSON description: not a value (‘unknown keyword or identifier’, u’not’) No JSON object could be decoded Trying to read null: ‘not a value’ Syntax error. Could not read ‘not a value’. Unacceptable JSON expression: not a value
6
"[]"
[] [] [] [] [] []
7
"[1]"
[1] [1] [1] [1] [1] [1]
8
"[1.1]"
[1.1000000000000001] [1.1000000000000001] [1.1000000000000001] [1.1000000000000001] [1.1000000000000001] [1.1000000000000001]
9
"[-1E+4]"
[-10000.0] [-10000.0] [-10000.0] Not a valid JSON array: ‘[-1E+4]‘ due to: ‘E’ [-10000.0] [-10000.0]
10
"[100.0e-2]"
[1.0] [1.0] [1.0] Not a valid JSON array: ‘[100.0e-2]‘ due to: ‘e’ [1.0] [1.0]
11
"[.5]"
cannot parse JSON description [0.5] Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[.5]‘ [0.5] [0.5]
12
"[5.]"
[5.0] (‘decimal point must be followed by at least one digit’, u’5.]’) Expecting , delimiter: line 1 column 3 (char 3) [5.0] [5.0] [5.0]
13
"[.]"
cannot parse JSON description (‘decimal point must be followed by at least one digit’, ‘.]’) Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[.]‘ Syntax error. Could not read ‘[.]‘. Unacceptable JSON expression: [.]
14
"[5..5]"
invalid number starting at position 1 (‘decimal point must be followed by at least one digit’, u’5..5]’) Expecting , delimiter: line 1 column 3 (char 3) Not a valid JSON number: ’5..5′ Syntax error. Could not read ‘[5..5]‘. Unacceptable JSON expression: [5..5]
15
"[10e]"
invalid number starting at position 1 (‘not a valid JSON numeric literal’, u”) Expecting , delimiter: line 1 column 4 (char 4) Not a valid JSON array: ‘[10e]‘ due to: ‘e’ Syntax error. Could not read ‘[10e]‘. Unacceptable JSON expression: [10e]
16
"[e10]"
cannot parse JSON description (‘unknown keyword or identifier’, u’e10′) Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[e10]‘ Strings must be quoted. Could not read ‘[e10]‘. Unacceptable JSON expression: [e10]
17
"[010e2]"
[1000.0] (‘initial zero digit must not be followed by other digits (octal numbers are not permitted)’, u’010e2]’) Expecting , delimiter: line 1 column 3 (char 3) Not a valid JSON array: ‘[010e2]‘ due to: ‘e’ [1000.0] [1000.0]
18
"[010.2]"
[10.199999999999999] (‘initial zero digit must not be followed by other digits (octal numbers are not permitted)’, u’010.2]’) Expecting , delimiter: line 1 column 3 (char 3) [10.199999999999999] [10.199999999999999] [10.199999999999999]
19
"[010]"
[10] (‘initial zero digit must not be followed by other digits (octal numbers are not permitted)’, u’010]’) Expecting , delimiter: line 1 column 3 (char 3) [10] [8] [10]
20
"[0xFF]"
cannot parse JSON description [255] Expecting , delimiter: line 1 column 3 (char 3) Not a valid JSON array: ‘[0xFF]‘ due to: ‘x’ [255] [255.0]
21
"[0xff]"
cannot parse JSON description [255] Expecting , delimiter: line 1 column 3 (char 3) Not a valid JSON array: ‘[0xff]‘ due to: ‘x’ [255] [255.0]
22
"[true]"
[True] [True] [True] [True] [True] [True]
23
"[TRUE]"
cannot parse JSON description (‘unknown keyword or identifier’, u’TRUE’) Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[TRUE]‘ Strings must be quoted. Could not read ‘[TRUE]‘. Unacceptable JSON expression: [TRUE]
24
"[null]"
[None] [None] [None] [None] [None] [None]
25
"[NULL]"
cannot parse JSON description: NULL] (‘unknown keyword or identifier’, u’NULL’) Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[NULL]‘ Strings must be quoted. Could not read ‘[NULL]‘. Unacceptable JSON expression: [NULL]
26
"[""]"
[''] [''] [u''] [''] [''] [u'']
27
"["a"]"
['a'] ['a'] [u'a'] ['a'] ['a'] [u'a']
28
" [ "a" ] "
['a'] ['a'] [u'a'] ['a'] ['a'] [u'a']
29
"[1,]"
expecting array item at position 3 [1] Expecting object: line 1 column 3 (char 3) Input is not valid JSON: ‘[1,]‘ [1] Unacceptable JSON expression: [1,]
30
"[,]"
expecting array item at position 1 [demjson.undefined] Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[,]‘ Syntax error. Could not read ‘[,]‘. Unacceptable JSON expression: [,]
31
"[,1]"
expecting array item at position 1 [demjson.undefined, 1] Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[,1]‘ Syntax error. Could not read ‘[,1]‘. Unacceptable JSON expression: [,1]
32
"[1,,1]"
expecting array item at position 3 [1, demjson.undefined, 1] Expecting object: line 1 column 3 (char 3) Input is not valid JSON: ‘[1,,1]‘ Syntax error. Could not read ‘[1,,1]‘. Unacceptable JSON expression: [1,,1]
33
"// comment here
[1]"
cannot parse JSON description [1] No JSON object could be decoded [1] [1] [1]
34
"[// comment here
1]"
cannot parse JSON description [1] Expecting object: line 1 column 1 (char 1) [1] [1] [1]
35
"[1// comment here
]"
cannot parse JSON description [1] Expecting , delimiter: line 1 column 3 (char 3) [1] [1] [1]
36
"[1]// comment here
"
extra data after JSON description at position 3 [1] Extra data: line 1 column 3 – line 2 column 1 (char 3 – 20) [1] Syntax error. Could not read ‘[1]// comment here’. Unacceptable JSON expression: [1]// comment here
37
"/*comment here*/[1]"
cannot parse JSON description [1] No JSON object could be decoded [1] [1] [1]
38
"[/*comment here*/1]"
cannot parse JSON description [1] Expecting object: line 1 column 1 (char 1) [1] [1] [1]
39
"[1/*comment here*/]"
cannot parse JSON description [1] Expecting , delimiter: line 1 column 3 (char 3) [1] [1] [1]
40
"[1]/*comment here*/"
extra data after JSON description at position 3 [1] Extra data: line 1 column 3 – line 1 column 19 (char 3 – 19) [1] [1] [1]
41
"/**/[1]"
cannot parse JSON description [1] No JSON object could be decoded [1] [1] [1]
42
"//
[1]"
cannot parse JSON description [1] No JSON object could be decoded [1] [1] [1]
43
"[1
// comment here
]"
cannot parse JSON description [1] Expecting , delimiter: line 2 column 2 (char 5) [1] Syntax error. Could not read ‘[1
]‘.
[1]
44
"[
// comment here
1]"
cannot parse JSON description [1] Expecting object: line 2 column 1 (char 3) [1] Syntax error. Could not read ‘[
1]‘.
[1]
45
"[1]// comment here"
extra data after JSON description at position 3 [1] Extra data: line 1 column 3 – line 1 column 18 (char 3 – 18) [1] Syntax error. Could not read ‘[1]// comment here’. Unacceptable JSON expression: [1]// comment here
46
"[1]
// comment here"
extra data after JSON description at position 5 [1] Extra data: line 2 column 1 – line 2 column 16 (char 5 – 20) [1] Syntax error. Could not read ‘[1]
// comment here’.
Unacceptable JSON expression: [1]
// comment here
47
"["a
// this is a comment
b"]"
['a\r\n// this is a comment\r\nb'] (‘line terminator characters must be escaped inside string literals’, u’\r\n// this is a comment\r\nb”]’) [u'a\r\n// this is a comment\r\nb'] ['a\r\n// this is a comment\r\nb'] Syntax error. Could not read ‘["a
b"]‘.
Unacceptable JSON expression: ["a
b"]
48
"["a // this is not a comment b"]"
['a // this is not a comment b'] ['a // this is not a comment b'] [u'a // this is not a comment b'] ['a // this is not a comment b'] ['a // this is not a comment b'] [u'a // this is not a comment b']
49
"['a']"
cannot parse JSON description ['a'] Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘['a']‘ ['a'] [u'a']
50
"["a]"
unterminated string starting at position 1 (‘string literal is not terminated with a quotation mark’, u’["a]‘) Unterminated string starting at: line 1 column 1 (char 1) Not a valid JSON string: ‘["a]‘ Syntax error. Could not read ‘["a]‘. Unacceptable JSON expression: ["a]
51
"[a"]"
cannot parse JSON description (‘unknown keyword or identifier’, u’a') Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[a"]‘ Syntax error. Could not read ‘[a"]‘. Unacceptable JSON expression: [a"]
52
"['a"]"
cannot parse JSON description (‘string literal is not terminated with a quotation mark’, u’[\'a"]‘) Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘['a"]‘ Syntax error. Could not read ‘['a"]‘. Unacceptable JSON expression: ['a"]
53
"["a']"
unterminated string starting at position 1 (‘string literal is not terminated with a quotation mark’, u’["a\']‘) Unterminated string starting at: line 1 column 1 (char 1) Not a valid JSON string: ‘["a']‘ Syntax error. Could not read ‘["a']‘. Unacceptable JSON expression: ["a']
54
"[']"
cannot parse JSON description (‘string literal is not terminated with a quotation mark’, “[']“) Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[']‘ Syntax error. Could not read ‘[']‘. Unacceptable JSON expression: [']
55
"['']"
cannot parse JSON description [''] Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘['']‘ [''] [u'']
56
"[''']"
cannot parse JSON description (‘string literal is not terminated with a quotation mark’, u”[''']“) Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘[''']‘ Syntax error. Could not read ‘[''']‘. <minjson.ListToken instance at 0x2b5b09e9edd0>
57
"["]"
unterminated string starting at position 1 (‘string literal is not terminated with a quotation mark’, ‘["]‘) Unterminated string starting at: line 1 column 1 (char 1) Not a valid JSON string: ‘["]‘ Syntax error. Could not read ‘["]‘. Unacceptable JSON expression: ["]
58
"["""]"
unterminated string starting at position 3 (‘string literal is not terminated with a quotation mark’, u’["""]‘) Expecting , delimiter: line 1 column 4 (char 4) Not a valid JSON array: ‘["""]‘ due to: ‘”‘ Syntax error. Could not read ‘["""]‘. <minjson.ListToken instance at 0x2b5b09e9ed88>
59
"["'"]"
["'"] ["'"] [u"'"] ["'"] ["'"] [u"'"]
60
"['"']"
cannot parse JSON description ['"'] Expecting object: line 1 column 1 (char 1) Input is not valid JSON: ‘['"']‘ ['"'] [u'"']
61
"["\'"]"
["\\'"] ["'"] Invalid \escape: “‘”: line 1 column 3 (char 3) Not a valid escaped JSON character: ”’ in ["\'"] ["'"] [u"\\'"]
62
"["\\'"]"
["\\'"] ["\\'"] [u"\\'"] ["\\'"] ["\\'"] [u"\\'"]
63
"["\""]"
['"'] ['"'] [u'"'] ['"'] ['"'] [u'"']
64
"["\"]"
unterminated string starting at position 1 (‘string literal is not terminated with a quotation mark’, u’["\\"]‘) Unterminated string starting at: line 1 column 1 (char 1) Not a valid JSON string: ‘["\"]‘ Syntax error. Could not read ‘["\"]‘. Unacceptable JSON expression: ["\"]
65
"["\\"]"
['\\'] ['\\'] [u'\\'] ['\\'] ['\\'] [u'\\']
66
"["\\\"]"
unterminated string starting at position 1 (‘string literal is not terminated with a quotation mark’, u’["\\\\\\"]‘) Unterminated string starting at: line 1 column 1 (char 1) Not a valid JSON string: ‘["\\\"]‘ Syntax error. Could not read ‘["\\\"]‘. Unacceptable JSON expression: ["\\\"]
67
"
["a"]"
['a'] ['a'] [u'a'] ['a'] ['a'] [u'a']
68
"[
"a"]"
['a'] ['a'] [u'a'] ['a'] Syntax error. Could not read ‘[
"a"]‘.
[u'a']
69
"["a
"]"
['a\r\n'] (‘line terminator characters must be escaped inside string literals’, u’\r\n”]’) [u'a\r\n'] ['a\r\n'] Syntax error. Could not read ‘["a
"]‘.
Unacceptable JSON expression: ["a
"]
70
"["a"
]"
['a'] ['a'] [u'a'] ['a'] Syntax error. Could not read ‘["a"
]‘.
[u'a']
71
"["a"]
"
['a'] ['a'] [u'a'] ['a'] ['a'] [u'a']
72
"["\u0041\u00DC"]"
[u'A\xdc'] [u'A\xdc'] [u'A\xdc'] [u'A\xdc'] ['\\u0041\\u00DC'] [u'A\xdc']
73
"["\b\t\f\v\r\n"]"
['\x08\t\x0c\x0b\r\n'] ['\x08\t\x0c\x0b\r\n'] Invalid \escape: ‘v’: line 1 column 9 (char 9) Not a valid escaped JSON character: ‘v’ in ["\b\t\f\v\r\n"] ['\x08\t\x0c\x0b\r\n'] [u'\x08\t\x0c\\v\r\n']
74
"["\b\t\f\r\n"]"
['\x08\t\x0c\r\n'] ['\x08\t\x0c\r\n'] [u'\x08\t\x0c\r\n'] ['\x08\t\x0c\r\n'] ['\x08\t\x0c\r\n'] [u'\x08\t\x0c\r\n']
75
"["\x41\xDC"]"
['\\x41\\xDC'] [u'A\xdc'] Invalid \escape: ‘x’: line 1 column 3 (char 3) Not a valid escaped JSON character: ‘x’ in ["\x41\xDC"] ['A\xdc'] [u'\\x41\\xDC']
76
"[ ] [ ]"
extra data after JSON description at position 4 (‘unexpected or extra text’, u’[ ]‘) Extra data: line 1 column 4 – line 1 column 7 (char 4 – 7) Input is not valid JSON: ‘[ ] [ ]‘ Syntax error. Could not read ‘[ ] [ ]‘. Unacceptable JSON expression: [ ] [ ]
77
"["a" "b"]"
['a', 'b'] ['a', 'b'] Expecting , delimiter: line 1 column 6 (char 6) Not a valid JSON array: ‘["a" "b"]‘ due to: ‘”‘ ['ab'] Unacceptable JSON expression: ["a" "b"]
78
"[1 2]"
[1, 2] [1, 2] Expecting , delimiter: line 1 column 4 (char 4) Not a valid JSON array: ‘[1 2]‘ due to: ’2′ Syntax error. Could not read ‘[1 2]‘. Unacceptable JSON expression: [1 2]
79
"[{}]"
[{}] [{}] [{}] [{}] [{}] [{}]
80
"[ { } ]"
[{}] [{}] [{}] Input is not valid JSON: ‘[ { } ]‘ [{}] [{}]
81
"[{1}]"
expecting property name in object at position 2 (‘object property (dictionary key) has no value, expected “:”‘, u’{1}]’) Expecting property name: line 1 column 2 (char 2) Not a valid JSON object key (should be a string): 1 Syntax error. Could not read ‘[{1}]‘. Unacceptable JSON expression: [{1}]
82
"[{1:1}]"
expecting property name in object at position 2 [{1: 1}] Expecting property name: line 1 column 2 (char 2) Not a valid JSON object key (should be a string): 1 [{1: 1}] Unacceptable JSON expression: [{1:1}]
83
"[{:1}]"
expecting property name in object at position 2 (‘can not decode value’, u’:1}]’) Expecting property name: line 1 column 2 (char 2) Input is not valid JSON: ‘[{:1}]‘ Syntax error. Could not read ‘[{:1}]‘. Unacceptable JSON expression: [{:1}]
84
"[{"1":}]"
cannot parse JSON description (‘can not decode value’, u’}]’) Expecting object: line 1 column 6 (char 6) Input is not valid JSON: ‘[{"1":}]‘ Syntax error. Could not read ‘[{"1":}]‘. Unacceptable JSON expression: [{"1":}]
85
"[{"1":1}]"
[{'1': 1}] [{'1': 1}] [{u'1': 1}] [{'1': 1}] [{'1': 1}] [{u'1': 1}]
86
"[{"":1}]"
[{'': 1}] [{'': 1}] [{u'': 1}] [{'': 1}] [{'': 1}] [{u'': 1}]
87
"[{"a":}]"
cannot parse JSON description (‘can not decode value’, u’}]’) Expecting object: line 1 column 6 (char 6) Input is not valid JSON: ‘[{"a":}]‘ Syntax error. Could not read ‘[{"a":}]‘. Unacceptable JSON expression: [{"a":}]
88
"[{"a":1}]"
[{'a': 1}] [{'a': 1}] [{u'a': 1}] [{'a': 1}] [{'a': 1}] [{u'a': 1}]
89
"[{"true":1}]"
[{'true': 1}] [{'true': 1}] [{u'true': 1}] [{'true': 1}] [{'true': 1}] [{u'true': 1}]
90
"[{true:1}]"
expecting property name in object at position 2 [{True: 1}] Expecting property name: line 1 column 2 (char 2) Not a valid JSON object key (should be a string): True [{True: 1}] Unacceptable JSON expression: [{true:1}]
91
"[{null:1}]"
expecting property name in object at position 2 (‘object properties (dictionary keys) must be either string literals or numbers’, u’{null:1}]’) Expecting property name: line 1 column 2 (char 2) Not a valid JSON object key (should be a string): None [{None: 1}] Unacceptable JSON expression: [{null:1}]
92
"[{a "a":1}]"
expecting property name in object at position 2 (‘object property (dictionary key) has no value, expected “:”‘, u’{a “a”:1}]’) Expecting property name: line 1 column 2 (char 2) Input is not valid JSON: ‘[{a "a":1}]‘ Syntax error. Could not read ‘[{a "a":1}]‘. Unacceptable JSON expression: [{a "a":1}]
93
"[{"a":1"a"}]"
missing colon after object property name at position 10 (‘object property (dictionary key) has no value, expected “:”‘, u’{“a”:1″a”}]’) Expecting , delimiter: line 1 column 7 (char 7) Not a valid JSON array: ‘[{"a":1"a"}]‘ due to: ‘”‘ Syntax error. Could not read ‘[{"a":1"a"}]‘. Unacceptable JSON expression: [{"a":1"a"}]
94
"[{a b:"a"}]"
expecting property name in object at position 2 (‘object property (dictionary key) has no value, expected “:”‘, u’{a b:”a”}]’) Expecting property name: line 1 column 2 (char 2) Input is not valid JSON: ‘[{a b:"a"}]‘ Syntax error. Could not read ‘[{a b:"a"}]‘. Unacceptable JSON expression: [{a b:"a"}]
95
"[{a b:a b}]"
expecting property name in object at position 2 (‘object property (dictionary key) has no value, expected “:”‘, u’{a b:a b}]’) Expecting property name: line 1 column 2 (char 2) Input is not valid JSON: ‘[{a b:a b}]‘ Syntax error. Could not read ‘[{a b:a b}]‘. Unacceptable JSON expression: [{a b:a b}]
96
"[{a 1:a 1}]"
expecting property name in object at position 2 (‘object property (dictionary key) has no value, expected “:”‘, u’{a 1:a 1}]’) Expecting property name: line 1 column 2 (char 2) Input is not valid JSON: ‘[{a 1:a 1}]‘ Syntax error. Could not read ‘[{a 1:a 1}]‘. Unacceptable JSON expression: [{a 1:a 1}]
97
"[{a:b:c}]"
expecting property name in object at position 2 (‘unknown keyword or identifier’, u’b') Expecting property name: line 1 column 2 (char 2) Input is not valid JSON: ‘[{a:b:c}]‘ Syntax error. Could not read ‘[{a:b:c}]‘. Unacceptable JSON expression: [{a:b:c}]
98
"[/*comment here*/{"1":1}]"
cannot parse JSON description [{'1': 1}] Expecting object: line 1 column 1 (char 1) [{'1': 1}] [{'1': 1}] [{u'1': 1}]
99
"[{/*comment here*/"1":1}]"
expecting property name in object at position 2 [{'1': 1}] Expecting property name: line 1 column 2 (char 2) [{'1': 1}] [{'1': 1}] [{u'1': 1}]
100
"[{"1"/*comment here*/:1}]"
missing colon after object property name at position 5 [{'1': 1}] Expecting : delimiter: line 1 column 5 (char 5) [{'1': 1}] [{'1': 1}] [{u'1': 1}]
101
"[{"1":/*comment here*/1}]"
cannot parse JSON description [{'1': 1}] Expecting object: line 1 column 6 (char 6) [{'1': 1}] [{'1': 1}] [{u'1': 1}]
102
"[{"1":1/*comment here*/}]"
expecting property name in object at position 7 [{'1': 1}] Expecting , delimiter: line 1 column 7 (char 7) [{'1': 1}] [{'1': 1}] [{u'1': 1}]
103
"[{"1":1}/*comment here*/]"
cannot parse JSON description [{'1': 1}] Expecting , delimiter: line 1 column 9 (char 9) [{'1': 1}] [{'1': 1}] [{u'1': 1}]

Final Notes

The above tables show that there are trade-offs between speed and
liberalness with input JSON. Fortunately, you can have it both ways! python-cjson
defines DecodeError, so your server can try: to decode with cjson, and if it fails,
you can handle the exception to use a more liberal translator. Choose your
secondary decoder by speed and/or how well it handles edge-case inputs from the
tables above. This page is largely automatically generated, (code available on request),
so this page can be re-done with additional or revised translators relatively quickly.
Just let me know if and when another run should be made.

I’m not altogether sure whether the above table shows any implementation bugs.
There seems to be a bit of disagreement in test case 73. I had started this evaluation for
personal reasons, but the results came out so interesting that I thought I would share.

This entry was posted in python. Bookmark the permalink.

Comments are closed.