Skip to content

JsonLayout Source

Bases: Enum

Layout of the rows of a JSON file, used by JsonReadOptions and JsonWriteOptions.

Added in version 0.1.0

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

folder = Path(tempfile.mkdtemp())
path = folder / "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))
print(path.read_text())
# {"price":1.5}
# {"price":8.0}

Attributes

RECORDS = auto() Source

One list holding one object per row: [{"city": "Paris"}, {"city": "Lyon"}]. Default value.

Added in version 0.1.0

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

folder = Path(tempfile.mkdtemp())
path = folder / "prices.json"
prices = ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5, 8.0])})
prices.to_json(path, ndp.JsonWriteOptions(layout=ndp.JsonLayout.RECORDS))
print(path.read_text())
# [{"price":1.5},{"price":8.0}]

LINES = auto() Source

One object per line, without enclosing list, also called JSON Lines.

Added in version 0.1.0

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

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