Skip to content

Commit 37ed5fc

Browse files
author
Sam Clift
committed
update based on PR feedback
1 parent 332fdcd commit 37ed5fc

File tree

1 file changed

+10
-49
lines changed

1 file changed

+10
-49
lines changed

docs/scenarios/json.rst

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
JSON
2-
===========
2+
====
33

4-
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.
95

106
Parsing JSON
117
------------
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:
1310

1411
.. code-block:: python
1512
@@ -21,7 +18,7 @@ Take the following string containing JSON data:
2118
2219
json_string = '{"first_name": "Guido", "last_name":"Rossum"}'
2320
24-
It can be manpulated like this:
21+
It can be parsed like this:
2522

2623
.. code-block:: python
2724
@@ -31,9 +28,10 @@ and can now be used as a normal dictionary:
3128

3229
.. code-block:: python
3330
34-
converted_dict['first_name']
31+
print(converted_dict['first_name'])
32+
"Guido"
3533
36-
As well as converting a JSON string to a dictionary. You can convert a dictionary to JSON:
34+
You can also convert a dictionary to JSON:
3735

3836
.. code-block:: python
3937
@@ -45,47 +43,10 @@ As well as converting a JSON string to a dictionary. You can convert a dictionar
4543
print(json.dumps(d))
4644
"{'first_name':'Guido','last_name':'Rossum'}"
4745
48-
We can also load a JSON file by using ``json.load`` instead of ``json.loads``:
49-
50-
.. code-block:: python
51-
52-
with file('path/to/file.json') as json_file:
53-
processed_json = json.load(json_file)
54-
55-
print(processsed_json)
56-
{u'first_name': u'Guido', u'last_name': u'Rossum'}
57-
58-
59-
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-
with file('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)
7046
7147
simplejson
7248
----------
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.
9049

50+
`simplejson <https://simplejson.readthedocs.org/en/latest/>`_ is the externally maintained development version of the json library.
9151

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

Comments
 (0)