Skip to main content
`Ctrl`+`K`

# pandas.api.typing.JsonReader

class pandas.api.typing.JsonReader(filepath_or_buffer, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, precise_float, date_unit, encoding, lines, chunksize, compression, nrows, storage_options=None, encoding_errors='strict', dtype_backend=<no_default>, engine='ujson')

  JsonReader provides an interface for reading in a JSON file.

  If initialized with `lines=True` and `chunksize`, can be iterated over `chunksize` lines at a time. Otherwise, calling `read` reads in the whole document.

  A `JsonReader` is returned by `read_json()` when `chunksize` is passed; it is not usually instantiated directly.

  Parameters:
    filepath_or_buffer a str path, path object or file-like object

      Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, ftp, s3, and file. pandas accepts any `os.PathLike`, or file-like object with a `read()` method, such as a file handle or `StringIO`.

    orient str

      Indication of expected JSON string format. Compatible JSON strings can be produced by `to_json()` with a corresponding orient value. See `read_json()` for the set of possible orients.

    typ{“frame”, “series”}

      The type of object to recover.

    dtype bool or dict

      If True, infer dtypes; if a dict of column to dtype, then use those; if False, then don’t infer dtypes at all, applies only to the data.

    convert_axes bool or None

      Try to convert the axes to the proper dtypes.

    convert_dates bool or list of str

      If True then default datelike columns may be converted (depending on `keep_default_dates`). If False, no dates will be converted. If a list of column names, then those columns will be converted and default datelike columns may also be converted (depending on `keep_default_dates`).

    keep_default_dates bool

      If parsing dates (`convert_dates` is not False), then try to parse the default datelike columns. See `read_json()` for the criteria used to determine whether a column label is datelike.

    precise_float bool

      Set to enable usage of higher precision (strtod) function when decoding string to double values.

    date_unit str or None

      The timestamp unit to detect if converting dates. The default behaviour is to try and detect the correct precision, but if this is not desired then pass one of ‘s’, ‘ms’, ‘us’ or ‘ns’ to force parsing only seconds, milliseconds, microseconds or nanoseconds respectively.

    encoding str or None

      The encoding to use to decode py3 bytes.

    lines bool

      Read the file as a json object per line.

    chunksize int or None

      Return a `JsonReader` for iteration, yielding `chunksize` lines at a time. Can only be passed if `lines=True`. If this is None, the file will be read into memory all at once.

    compression str or dict

      For on-the-fly decompression of on-disk data, see `read_json()` for the accepted values.

    nrows int or None

      The number of lines from the line-delimited json file that has to be read. Can only be passed if `lines=True`. If this is None, all the rows will be returned.

    storage_options dict, optional

      Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. See `read_json()` for more details.

    encoding_errors str, optional, default “strict”

      How encoding errors are treated. List of possible values .

    dtype_backend{“numpy_nullable”, “pyarrow”}

      Back-end data type applied to the resultant `DataFrame` (still experimental). See `read_json()` for more details.

    engine{“ujson”, “pyarrow”}, default “ujson”

      Parser engine to use. See `read_json()` for the restrictions on the `"pyarrow"` engine.

  See also

  `read_json`

    Convert a JSON string to pandas object.

  Examples

      >>> from io import StringIO
      >>> df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
      >>> reader = pd.read_json(
      ...     StringIO(df.to_json(orient="records", lines=True)),
      ...     lines=True,
      ...     chunksize=1,
      ... )
      >>> for chunk in reader:
      ...     print(chunk)
         a  b
      0  1  3
         a  b
      1  2  4

  Methods

  `close`() | Close the underlying file handle, if one was opened by the reader.
  `read`() | Read the whole JSON input into a pandas object.