New submission from Tomasz Buchert <thin...@gmail.com>: 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 ---------- components: Library (Lib) messages: 145847 nosy: thinred priority: normal severity: normal status: open title: json library is decoding/encoding when it should not versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13212> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com