You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `json <https://docs.python.org/2/library/json.html>`_ library can read JSON strings into a Python dictionary or list. It can also serialize Python dictionaries or lists into JSON strings.
5
-
6
-
* There are six basic types in JSON: objects, lists, numbers, strings, booleans, and null.
7
-
* The root element of JSON representation is an object, signified by ``{ ... }``. JSON objects are analogous to Python dictionaries: they have keys which correspond to values.
8
-
* JSON does not use single quotes. JSON exclusively uses double quotes. Using single quotes in the place of double quotes is invalid JSON syntax.
4
+
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.
9
5
10
6
Parsing JSON
11
7
------------
12
-
The `json <https://docs.python.org/2/library/json.html>`_ libary is imported like this:
8
+
9
+
The json libary is imported like this:
13
10
14
11
.. code-block:: python
15
12
@@ -21,7 +18,7 @@ Take the following string containing JSON data:
Here's an example of writing directly to a file by using ``json.dump`` instead of ``json.dumps``:
60
-
61
-
.. code-block:: python
62
-
63
-
withfile('path/to/file.json', 'w') as json_file:
64
-
dict= {
65
-
"first_name": "Guido",
66
-
"last_name": "Rossum",
67
-
"middle_name": "Van"
68
-
}
69
-
json.dump(dict, json_file)
70
46
71
47
simplejson
72
48
----------
73
-
`simplejson <https://simplejson.readthedocs.org/en/latest/>`_ is the externally maintained development version of the json library.
74
-
75
-
simplejson mimics the json standard library, so you can start using simplejson instead of json by importing it under a different name
76
-
77
-
Installation
78
-
79
-
.. code-block:: python
80
-
81
-
pip install simplejson
82
-
83
-
Usage
84
-
85
-
.. code-block:: python
86
-
87
-
import simplejson as json
88
-
89
-
simplejson is available so that developers that use an older version of python can use the latest features available in the json lib.
90
49
50
+
`simplejson <https://simplejson.readthedocs.org/en/latest/>`_ is the externally maintained development version of the json library.
91
51
52
+
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.
0 commit comments