]> granicus.if.org Git - python/commitdiff
Issue #21514: The documentation of the json module now refers to new JSON RFC
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 27 Nov 2014 17:45:31 +0000 (19:45 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 27 Nov 2014 17:45:31 +0000 (19:45 +0200)
7159 instead of obsoleted RFC 4627.

1  2 
Doc/library/json.rst
Misc/NEWS

index edbc5e0bd5a80ef8c0d12d05766b3c662a7c9ad9,33ad102e6f4bf8edb2bad1634e21d742addbb6d7..c77b89ed6b529bbbba13f95f4ff8c15a5e5ec568
@@@ -566,64 -552,47 +554,109 @@@ the last name-value pair for a given na
  
  The *object_pairs_hook* parameter can be used to alter this behavior.
  
+ Top-level Non-Object, Non-Array Values
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ The old version of JSON specified by the obsolete :rfc:`4627` required that
+ the top-level value of a JSON text must be either a JSON object or array
+ (Python :class:`dict` or :class:`list`), and could not be a JSON null,
+ boolean, number, or string value.  :rfc:`7159` removed that restriction, and
+ this module does not and has never implemented that restriction in either its
+ serializer or its deserializer.
+ Regardless, for maximum interoperability, you may wish to voluntarily adhere
+ to the restriction yourself.
+ Implementation Limitations
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ Some JSON deserializer implementations may set limits on:
+ * the size of accepted JSON texts
+ * the maximum level of nesting of JSON objects and arrays
+ * the range and precision of JSON numbers
+ * the content and maximum length of JSON strings
+ This module does not impose any such limits beyond those of the relevant
+ Python datatypes themselves or the Python interpreter itself.
+ When serializing to JSON, beware any such limitations in applications that may
+ consume your JSON.  In particular, it is common for JSON numbers to be
+ deserialized into IEEE 754 double precision numbers and thus subject to that
+ representation's range and precision limitations.  This is especially relevant
+ when serializing Python :class:`int` values of extremely large magnitude, or
+ when serializing instances of "exotic" numerical types such as
+ :class:`decimal.Decimal`.
 +.. highlight:: bash
 +.. module:: json.tool
 +
 +.. _json-commandline:
 +
 +Command Line Interface
 +----------------------
 +
 +The :mod:`json.tool` module provides a simple command line interface to validate
 +and pretty-print JSON objects.
 +
 +If the optional ``infile`` and ``outfile`` arguments are not
 +specified, :attr:`sys.stdin` and :attr:`sys.stdout` will be used respectively::
 +
 +    $ echo '{"json": "obj"}' | python -m json.tool
 +    {
 +        "json": "obj"
 +    }
 +    $ echo '{1.2:3.4}' | python -m json.tool
 +    Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
 +
 +.. versionchanged:: 3.5
 +   The output is now in the same order as the input. Use the
 +   :option:`--sort-keys` option to sort the output of dictionaries
 +   alphabetically by key.
 +
 +Command line options
 +^^^^^^^^^^^^^^^^^^^^
 +
 +.. cmdoption:: infile
 +
 +   The JSON file to be validated or pretty-printed::
 +
 +      $ python -m json.tool mp_films.json
 +      [
 +          {
 +              "title": "And Now for Something Completely Different",
 +              "year": 1971
 +          },
 +          {
 +              "title": "Monty Python and the Holy Grail",
 +              "year": 1975
 +          }
 +      ]
 +
 +   If *infile* is not specified, read from :attr:`sys.stdin`.
 +
 +.. cmdoption:: outfile
 +
 +   Write the output of the *infile* to the given *outfile*. Otherwise, write it
 +   to :attr:`sys.stdout`.
 +
 +.. cmdoption:: --sort-keys
 +
 +   Sort the output of dictionaries alphabetically by key.
 +
 +   .. versionadded:: 3.5
 +
 +.. cmdoption:: -h, --help
 +
 +   Show the help message.
++
+ .. rubric:: Footnotes
+ .. [#rfc-errata] As noted in `the errata for RFC 7159
+    <http://www.rfc-editor.org/errata_search.php?rfc=7159>`_,
+    JSON permits literal U+2028 (LINE SEPARATOR) and
+    U+2029 (PARAGRAPH SEPARATOR) characters in strings, whereas JavaScript
+    (as of ECMAScript Edition 5.1) does not.
diff --cc Misc/NEWS
index db6daed62bf5023c02df6c4c12237e19e47368dc,c1abebed31142682edcaaef3d67f3e40f509eb81..c005a6f310fa38e54d11b27d6e8f8d4448b6e1ae
+++ b/Misc/NEWS
@@@ -1300,12 -974,6 +1300,15 @@@ C AP
  Documentation
  -------------
  
++- Issue #21514: The documentation of the json module now refers to new JSON RFC
++  7159 instead of obsoleted RFC 4627.
++
 +- Issue #21777: The binary sequence methods on bytes and bytearray are now
 +  documented explicitly, rather than assuming users will be able to derive
 +  the expected behaviour from the behaviour of the corresponding str methods.
 +
 +- Issue #6916: undocument deprecated asynchat.fifo class.
 +
  - Issue #17386: Expanded functionality of the ``Doc/make.bat`` script to make
    it much more comparable to ``Doc/Makefile``.