Version: latest
agrag.loaders.records.JsonLoader
Bases: RecordLoader
Reads JSON files, disambiguating arrays from objects.
Attributes:
- extensions – The
.jsonextension.
Functions:
- is_available – Return whether the package that the loader's extra installs is present.
- load – Yield documents from a JSON source.
extensions
extensions = frozenset({'.json'})
extra
extra: str | None = None
extra_module
extra_module: str | None = None
family
family = DocumentFamily.RECORD
is_available
is_available() -> bool
Return whether the package that the loader's extra installs is present.
A loader with no extra is always available. The check looks the module up without importing it, so an installed package that fails to import still counts.
load
load(source:SourceRef, stream:BinaryIO, opts:ReadOptions, *, start_at:int = 0) -> Iterator[Document]
Yield documents from a JSON source.
A top-level array becomes one record Document per element, unless json_mode
is
DOCUMENT, which yields one prose Document holding the whole array. A
top-level
object becomes one prose Document.
Parameters:
- source (
SourceRef) – The source to read. - stream (
BinaryIO) – The open binary stream for the source. - opts (
ReadOptions) – The read options.json_modeoverrides the sniff. - start_at (
int) – The record index to resume from (arrays only).
Yields:
Document– One or more Documents, in file order.
Raises:
MalformedRecordError– The source is not valid JSON.
mime_types
mime_types: frozenset[str] = frozenset()