[Python-3000-checkins] r63259 - python/branches/py3k/Doc/library/json.rst

benjamin.peterson python-3000-checkins at python.org
Thu May 15 04:17:58 CEST 2008


Author: benjamin.peterson
Date: Thu May 15 04:17:58 2008
New Revision: 63259

Log:
Fix json examples so they would actually work in Py3k


Modified:
   python/branches/py3k/Doc/library/json.rst

Modified: python/branches/py3k/Doc/library/json.rst
==============================================================================
--- python/branches/py3k/Doc/library/json.rst	(original)
+++ python/branches/py3k/Doc/library/json.rst	Thu May 15 04:17:58 2008
@@ -19,13 +19,13 @@
     '["foo", {"bar": ["baz", null, 1.0, 2]}]'
     >>> print(json.dumps("\"foo\bar"))
     "\"foo\bar"
-    >>> print(json.dumps(u'\u1234'))
+    >>> print(json.dumps('\u1234'))
     "\u1234"
     >>> print(json.dumps('\\'))
     "\\"
     >>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
     {"a": 0, "b": 0, "c": 0}
-    >>> from StringIO import StringIO
+    >>> from io import StringIO
     >>> io = StringIO()
     >>> json.dump(['streaming API'], io)
     >>> io.getvalue()
@@ -50,13 +50,13 @@
     
     >>> import json
     >>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
-    [u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
+    ['foo', {'bar': ['baz', None, 1.0, 2]}]
     >>> json.loads('"\\"foo\\bar"')
-    u'"foo\x08ar'
-    >>> from StringIO import StringIO
+    '"foo\x08ar'
+    >>> from io import StringIO
     >>> io = StringIO('["streaming API"]')
     >>> json.load(io)
-    [u'streaming API']
+    ['streaming API']
 
 Specializing JSON object decoding::
 
@@ -65,7 +65,7 @@
     ...     if '__complex__' in dct:
     ...         return complex(dct['real'], dct['imag'])
     ...     return dct
-    ... 
+    ...
     >>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
     ...     object_hook=as_complex)
     (1+2j)
@@ -81,7 +81,7 @@
     ...         if isinstance(obj, complex):
     ...             return [obj.real, obj.imag]
     ...         return json.JSONEncoder.default(self, obj)
-    ... 
+    ...
     >>> dumps(2 + 1j, cls=ComplexEncoder)
     '[2.0, 1.0]'
     >>> ComplexEncoder().encode(2 + 1j)


More information about the Python-3000-checkins mailing list