etl_lib.task.data_loading.JSONLoad2Neo4jTask module
- class JSONLoad2Neo4jTask(context, file, model=None, batch_size=5000)[source]
Bases:
TaskLoads 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 optionalijsondependency.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 theETL_ERROR_PATHcontext env var when set, otherwise next to the input file with.error.jsonappended.Subclasses must implement
_query(), returning Cypher that starts withUNWIND $batch AS row.Validation round-trips each record through the Pydantic model. Source-injected fields such as the
_rowfield added byJSONBatchSourcetherefore reach the query only when no model is given. With a model,row._rowis absent and Cypher yieldsnullfor it rather than raising.- Parameters:
context (ETLContext)
file (Path)
batch_size (int)
- __init__(context, file, model=None, batch_size=5000)[source]
Construct a Task object.
- Parameters:
context (
ETLContext) –ETLContextinstance. Will be available to subclasses.file (Path)
batch_size (int)
- 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:
- Returns:
An instance of
TaskReturn.