JsonConnector¶
JSON / JSONL source connector.
- class scamander.sources.json_connector.JsonConnector(config: Config, *args, **kwargs)¶
Bases:
SourceSource connector that reads JSON files into a Spark DataFrame.
Uses Spark’s built-in JSON reader, which supports:
Single JSON objects or arrays at the root level (
multiline=True).JSONL / NDJSON format — one JSON record per line (
multiline=False, the default).Directories containing multiple JSON files.
Glob patterns (e.g.
"dbfs:/mnt/raw/events/*.json").
Spark reads all matching files into a single DataFrame, inferring a common schema across all records.
Can be instantiated directly with flat keyword arguments, or via the
Sourcefactory (Source(config, spark=spark)) by passing aConfigwhosesource.optionsis aJsonSourceOptions.- Parameters:
file_path (str | Config) – Path, directory, or glob pattern to the JSON source(s), or a validated
Configwhosesource.optionsis aJsonSourceOptions(theSourcefactory path — requiressparkas a keyword argument).multiline (bool) –
Truefor multi-line JSON objects/arrays per file.False(default) for JSONL where each line is a record. Ignored whenfile_pathis aConfig.infer_schema (bool) – Infer column types from the data. Defaults to
True. Set toFalseto read all fields asSTRING. Ignored whenfile_pathis aConfig.encoding (str) – Character encoding of the files. Defaults to
"UTF-8". Ignored whenfile_pathis aConfig.spark (SparkSession) – Required keyword argument when
file_pathis aConfig; unused otherwise.
- Raises:
ValueError – If
file_pathis aConfigwhosesource.optionsis not aJsonSourceOptionsinstance.
- connect() DataFrame¶
Read the JSON file(s) into a Spark DataFrame.
- Returns:
DataFrame with one row per JSON record (JSONL) or one row per top-level object/array element (multiline mode).