Skip to content

JsonWriteOptions(layout=JsonLayout.RECORDS, decimals=None) Source

Settings of a JSON file written by Table.to_json.

JSON files are always written in UTF-8.

Added in version 0.1.0

Parameters:

  • layout (JsonLayout, default: JsonLayout.RECORDS)

    The layout of the rows, one list of objects by default.

  • decimals (int | None, default: None)

    The number of decimals written for every decimal column, 0 or more. Each value is rounded and keeps its zeros, such as 1.50, so the file no longer holds the exact values. When omitted, a decimal is written with every digit of its value.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.jsonl"
prices = ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5, 8.0])})
prices.to_json(path, ndp.JsonWriteOptions(layout=ndp.JsonLayout.LINES, decimals=2))
print(path.read_text())
# {"price":1.50}
# {"price":8.00}
#