Message145847
| Author |
thinred |
| Recipients |
thinred |
| Date |
2011年10月18日.18:00:31 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1318960832.41.0.586770861075.issue13212@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Hi there!
According to http://www.ietf.org/rfc/rfc4627.txt . The JSON object is either a list or a dictionary with other elements in it. However Python's implementation took liberty to parse also basic types, like integers, strings, floats, etc. For example:
>>> import json
>>> json.loads('42')
42
>>> json.dumps(3.141592)
'3.141592'
It wouldn't be a problem if other implementations would adhere to this behavior, but this is not true. Take Ruby for example:
irb(main):007:0> require 'rubygems';
irb(main):008:0* require 'json';
irb(main):009:0* JSON.parse '42'
JSON::ParserError: 743: unexpected token at '42'
from /var/lib/gems/1.8/gems/json-1.6.1/lib/json/common.rb:148:in `parse'
from /var/lib/gems/1.8/gems/json-1.6.1/lib/json/common.rb:148:in `parse'
from (irb):9
from :0
irb(main):010:0> JSON.generate(3.141592)
JSON::GeneratorError: only generation of JSON objects or arrays allowed
from /var/lib/gems/1.8/gems/json-1.6.1/lib/json/common.rb:216:in `generate'
from /var/lib/gems/1.8/gems/json-1.6.1/lib/json/common.rb:216:in `generate'
from (irb):10
from :0
Also http://jsonlint.com/ considers it an error.
I know this is not very important, but I've ran into this today when trying to parse JSON in Ruby which was produced in Python.
I've made a patch for that, but I still need to fix tests and there are many of them. I first would like to know if it is going to be fixed, then I will complete the patch.
Thanks for Python, anyway!
Tomek |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2011年10月18日 18:00:32 | thinred | set | recipients:
+ thinred |
| 2011年10月18日 18:00:32 | thinred | set | messageid: <1318960832.41.0.586770861075.issue13212@psf.upfronthosting.co.za> |
| 2011年10月18日 18:00:31 | thinred | link | issue13212 messages |
| 2011年10月18日 18:00:31 | thinred | create |
|