etl_lib.task.data_loading.JSONLoad2Neo4jTask module

class JSONLoad2Neo4jTask(context, file, model=None, batch_size=5000)[source]

Bases: Task

Loads the specified JSON file to Neo4j.

See Building pipelines for the conventions a load task follows.

Accepts both layouts supported by JSONBatchSource: JSON Lines and a single JSON array of objects. Array input requires the optional ijson dependency.

The pipeline mirrors CSVLoad2Neo4jTask: read in batches, optionally validate each record against a Pydantic model, and write to Neo4j via the subclass-provided Cypher query. Records failing validation go to an error file located exactly as in the CSV task: under the ETL_ERROR_PATH context env var when set, otherwise next to the input file with .error.json appended.

Subclasses must implement _query(), returning Cypher that starts with UNWIND $batch AS row.

Validation round-trips each record through the Pydantic model. Source-injected fields such as the _row field added by JSONBatchSource therefore reach the query only when no model is given. With a model, row._row is absent and Cypher yields null for it rather than raising.

Parameters:
__init__(context, file, model=None, batch_size=5000)[source]

Construct a Task object.

Parameters:
run_internal(**kwargs)[source]

Place to provide the logic to be performed.

This base class provides all the housekeeping and reporting, so that implementation must/should not need to care about them. Exceptions should not be captured by implementations. They are handled by this base class.

Parameters:

kwargs – will be passed to run_internal

Return type:

TaskReturn

Returns:

An instance of TaskReturn.