DBNStore.to_json

Write data to a file in JSON format.

Parameters

Parameter
Type
Required
Description
path
PathLike[str] or str
required
The file path to write to.
pretty_ts
bool, default True
optional
Whether timestamp columns are converted to tz-aware pandas.Timestamp (UTC).
pretty_px
bool, default True
optional
Whether price columns are correctly scaled as display prices.
map_symbols
bool, default True
optional
If symbology mappings from the metadata should be used to create a 'symbol' column, mapping the instrument ID to its raw symbol for every record.
compression
Compression or str
optional
The output compression for writing. Must be either 'zstd' or 'none'.
schema
Schema or str
optional
The data record schema for the output JSON. Must be one of the values from list_schemas. This is only required when reading a DBNStore with mixed record types.
mode
str
optional
The file write mode to use, either "x" or "w". Defaults to "w".

Returns

None

API method
1
2
3
4
5
6
7
8
9
DBNStore.to_json(
    path: PathLike[str] | str,
    pretty_ts: bool = True,
    pretty_px: bool = True,
    map_symbols: bool = True,
    compression: Compression | str = Compression.NONE,
    schema: Schema | str | None = None,
    mode: Literal["w", "x"] = "w",
) -> None
Example usage
1
2
3
4
5
6
7
8
9
10
11
12
13
import databento as db

client = db.Historical("$YOUR_API_KEY")

data = client.timeseries.get_range(
    dataset="GLBX.MDP3",
    symbols=["ESM2"],
    schema="trades",
    start="2022-06-06",
)

# Save streamed data to .json
data.to_json("GLBX-ESM2-20220606-trades.json")