Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(521)

Unified Diff: Lib/json/__init__.py

Issue 7311: [issue4136] merge json library with simplejson 2.0.3 Base URL: http://svn.python.org/view/*checkout*/python/trunk/
Patch Set: Created 5 years, 6 months ago , Downloaded from: http://bugs.python.org/file11822/json_issue4136_r66961.diff
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/json/decoder.py » ('j') | Lib/json/decoder.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Lib/json/__init__.py
===================================================================
--- Lib/json/__init__.py (revision 66961)
+++ Lib/json/__init__.py (working copy)
@@ -29,8 +29,10 @@
Compact encoding::
>>> import json
- >>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
- '[1,2,3,{"4":5,"6":7}]'
+ >>> compact = json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
+ >>> # Can't assume dict ordering
+ >>> compact in ('[1,2,3,{"4":5,"6":7}]', '[1,2,3,{"6":7,"4":5}]')
+ True
Pretty printing (using repr() because of extraneous whitespace in the output)::
@@ -41,14 +43,14 @@
Decoding JSON::
>>> import json
- >>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
- [u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
- >>> json.loads('"\\"foo\\bar"')
- u'"foo\x08ar'
+ >>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]') == ["foo", {"bar":["baz", None, 1.0, 2]}]
+ True
+ >>> json.loads('"\\"foo\\bar"') == '"foo\x08ar'
+ True
>>> from StringIO import StringIO
>>> io = StringIO('["streaming API"]')
- >>> json.load(io)
- [u'streaming API']
+ >>> json.load(io) == ["streaming API"]
+ True
Specializing JSON object decoding::
@@ -61,9 +63,9 @@
>>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
... object_hook=as_complex)
(1+2j)
- >>> import decimal
- >>> json.loads('1.1', parse_float=decimal.Decimal)
- Decimal('1.1')
+ >>> from decimal import Decimal
+ >>> json.loads('1.1', parse_float=Decimal) == Decimal("1.1")
+ True
Extending JSONEncoder::
@@ -78,8 +80,8 @@
'[2.0, 1.0]'
>>> ComplexEncoder().encode(2 + 1j)
'[2.0, 1.0]'
- >>> list(ComplexEncoder().iterencode(2 + 1j))
- ['[', '2.0', ', ', '1.0', ']']
+ >>> ''.join(ComplexEncoder().iterencode(2 + 1j))
+ '[2.0, 1.0]'
Using json.tool from the shell to validate and
@@ -96,8 +98,7 @@
is a subset of YAML, so it may be used as a serializer for that as well.
"""
-
-__version__ = '1.9'
+__version__ = '2.0.3'
__all__ = [
'dump', 'dumps', 'load', 'loads',
'JSONDecoder', 'JSONEncoder',
« no previous file with comments | « no previous file | Lib/json/decoder.py » ('j') | Lib/json/decoder.py » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1278:e6ce13d99bf5