mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Merge pull request #515 from mplewis/improve_json_section
Improve json section
This commit is contained in:
+12
-4
@@ -1,7 +1,7 @@
|
||||
JSON
|
||||
====
|
||||
|
||||
The `json <https://docs.python.org/2/library/json.html>`_ library can parse JSON from strings or files. When parsing, the library converts the JSON into a Python dictionary or list. It can also parse Python dictionaries or lists into JSON strings.
|
||||
The `json <https://docs.python.org/2/library/json.html>`_ library can parse JSON from strings or files. The library parses JSON into a Python dictionary or list. It can also convert Python dictionaries or lists into JSON strings.
|
||||
|
||||
Parsing JSON
|
||||
------------
|
||||
@@ -26,7 +26,7 @@ and can now be used as a normal dictionary:
|
||||
print(parsed_json['first_name'])
|
||||
"Guido"
|
||||
|
||||
You can also convert a the following to JSON:
|
||||
You can also convert the following to JSON:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -43,6 +43,14 @@ You can also convert a the following to JSON:
|
||||
simplejson
|
||||
----------
|
||||
|
||||
`simplejson <https://simplejson.readthedocs.org/en/latest/>`_ is the externally maintained development version of the json library.
|
||||
The JSON library was added to Python in version 2.6. If you're using an earlier version of Python, the `simplejson <https://simplejson.readthedocs.org/en/latest/>`_ library is available via PyPI.
|
||||
|
||||
simplejson mimics the json standard library, it is available so that developers that use an older version of python can use the latest features available in the json lib.
|
||||
simplejson mimics the json standard library. It is available so that developers that use older versions of Python can use the latest features available in the json lib.
|
||||
|
||||
You can start using simplejson when the json library is not available by importing simplejson under a different name:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import simplejson as json
|
||||
|
||||
After importing simplejson as json, the above examples will all work as if you were using the standard json library.
|
||||
|
||||
Reference in New Issue
Block a user