Skip to content

Commit a9dafe3

Browse files
committed
DOC: io.rst doc updates
1 parent 7dd12cc commit a9dafe3

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

doc/source/io.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,22 @@ Read and write ``JSON`` format files.
949949

950950
Writing JSON
951951
~~~~~~~~~~~~
952+
953+
A ``Series`` or ``DataFrame`` can be converted to a valid JSON string. Use ``to_json``
954+
with optional parameters:
955+
956+
- orient : The format of the JSON string, default is ``index`` for ``Series``, ``columns`` for ``DataFrame``
957+
958+
* split : dict like {index -> [index], columns -> [columns], data -> [values]}
959+
* records : list like [{column -> value}, ... , {column -> value}]
960+
* index : dict like {index -> {column -> value}}
961+
* columns : dict like {column -> {index -> value}}
962+
* values : just the values array
963+
964+
- double_precision : The number of decimal places to use when encoding floating point values, default 10.
965+
- force_ascii : force encoded string to be ASCII, default True.
966+
967+
Note NaN's and None will be converted to null and datetime objects will be converted to UNIX timestamps.
952968

953969
.. ipython:: python
954970
@@ -959,6 +975,24 @@ Writing JSON
959975
Reading JSON
960976
~~~~~~~~~~~~
961977

978+
Reading a JSON string to pandas object can take a number of parameters.
979+
The parser will try to parse a ``DataFrame`` if ``typ`` is not supplied or
980+
is ``None``. To explicity force ``Series`` parsing, pass ``typ=series``
981+
982+
- json : The JSON string to parse.
983+
- typ : type of object to recover (series or frame), default 'frame'
984+
- orient : The format of the JSON string, one of the following
985+
986+
* split : dict like {index -> [index], name -> name, data -> [values]}
987+
* records : list like [value, ... , value]
988+
* index : dict like {index -> value}
989+
990+
- dtype : dtype of the resulting Series
991+
- numpy : direct decoding to numpy arrays. default True but falls back to standard decoding if a problem occurs.
992+
993+
The parser will raise one of ``ValueError/TypeError/AssertionError`` if the JSON is
994+
not parsable.
995+
962996
.. ipython:: python
963997
964998
pd.read_json(s)

pandas/io/json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def to_json(obj, orient=None, double_precision=10,
3636
-------
3737
result : JSON compatible string
3838
"""
39+
3940
if orient is None:
4041
if isinstance(obj, Series):
4142
orient = 'index'
@@ -60,7 +61,7 @@ def read_json(json, typ='frame', orient=None, dtype=None, numpy=True):
6061
records : list like [value, ... , value]
6162
index : dict like {index -> value}
6263
dtype : dtype of the resulting Series
63-
nupmpy: direct decoding to numpy arrays. default True but falls back
64+
numpy: direct decoding to numpy arrays. default True but falls back
6465
to standard decoding if a problem occurs.
6566
6667
Returns

0 commit comments

Comments
 (0)