Skip to main content

FileLoader JSON

JSON file loader for the vcti-fileloader framework — parses with the stdlib json module and attaches the parsed object as a single locked subtree under a caller-supplied parent.

Overview

vcti-fileloader-json is a JSON loader plugin for the vcti-fileloader framework. It implements the Loader protocol: populate(handle, tree, parent) parses a JSON file with the Python standard library json module and attaches the parsed value (a dict, list, scalar, or None) as the .data of a single child under a one-node subtree. The returned subtree is structure-locked and payload-locked.

The package depends only on vcti-fileloader and vcti-tree; the JSON parser is the Python stdlib. JSON files have no native attribute mechanism, so the loader stamps no file_attributes — callers that want to enrich with file paths, tags, or derived metadata should use the before_lock hook on populate.

Installation

pip install vcti-fileloader-json>=1.0.3

In pyproject.toml dependencies

dependencies = [
    "vcti-fileloader-json>=1.0.3",
]

Quick Start

from pathlib import Path

from vcti.fileloader.core import DataNode
from vcti.fileloader.json import JsonLoader
from vcti.tree.core import DictTree

loader = JsonLoader()
tree: DictTree[DataNode] = DictTree(DataNode())

with loader.open(Path("config.json")) as handle:
    subtree_root = loader.populate(handle, tree, tree.root_handle)

# The parsed object lives on the single child's `.data`.
[child_handle] = tree.children(subtree_root)
parsed = tree.payload(child_handle).data
print(parsed)               # e.g. {"name": "demo", "values": [1, 2, 3]}

With a before_lock hook

JSON has no native attribute mechanism, so all attribute stamping happens via the hook. A typical pattern is to attach the file path:

path = Path("config.json")

def stamp_file_path(tree, root):
    tree.payload(root).enricher_attributes["file_path"] = str(path)

with loader.open(path) as handle:
    root = loader.populate(handle, tree, tree.root_handle, before_lock=stamp_file_path)

For rule-driven enrichment, pair the hook with vcti-attribute-enricher.


What the subtree looks like

For any JSON file (whether it parses to a dict, list, scalar, or null), the subtree shape is uniform:

Node name Payload data file_attributes
subtree root None DataNode None {}
child None DataNode the parsed object/value {}

The root's payload is an empty DataNode (data is None, no attributes) — it exists to give callers a single locked anchor regardless of the parsed value's type. The child carries the parsed value as .data.


API

JsonLoader

Method Description
load(path, **options) Parse the JSON file; return a parser handle
open(path, **options) Context manager — load and auto-unload
populate(handle, tree, parent, *, before_lock=None, **options) Attach the parsed object as a single locked subtree
unload(handle) No-op (parsed result is in-memory; nothing to release)
can_load(path) Check extension (.json)

Helpers

Description
get_loader_descriptor() Create LoaderDescriptor for registry
JsonValidator Verify the stdlib json module is importable
JsonSetup No-op setup

Error Handling

from vcti.fileloader.core import (
    LoadError,
    UnsupportedFormatError,
    TreeAttachmentError,
)

try:
    with loader.open(Path("config.json")) as handle:
        subtree_root = loader.populate(handle, tree, tree.root_handle)
except FileNotFoundError:
    ...
except UnsupportedFormatError:
    # File extension is not .json
    ...
except LoadError:
    # File could not be opened or contained invalid JSON
    ...
except TreeAttachmentError:
    # parent is missing, deleted, or structure-locked in `tree`
    ...

If populate fails partway (an invalid JSON token, or a before_lock exception), the partial subtree is removed before the exception propagates — callers never see a half-built subtree.


What this package does NOT do

  • Streaming parses. json.load reads the whole file at once. Use a streaming JSON parser (e.g. ijson) and a custom loader for very large files.
  • Schema validation. The loader accepts any well-formed JSON. Validation belongs in a before_lock hook or downstream pass.
  • Expand JSON into a multi-node tree. The parsed object lands on a single leaf as a Python object. If you want each JSON key as a separate tree node, that is a separate (future) loader; this one is deliberately one-node.

Dependencies

  • vcti-fileloader (>=5.1.0) — Loader protocol, SubtreeBuilder, DataNode (import from vcti.fileloader.core)
  • vcti-tree (>=1.0.0) — LockableTree protocol

The JSON parser is json from the Python standard library — no third-party dependency.

Metadata

Release files for vcti-fileloader-json 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vcti-fileloader-json 1.0.3
File Size Uploaded
vcti_fileloader_json-1.0.3.tar.gz 10.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vcti-fileloader-json 1.0.3
File Interpreter ABI Platform
vcti_fileloader_json-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / vcti_fileloader_json-1.0.3.tar.gz

Download URL vcti_fileloader_json-1.0.3.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
67a6fed52d139266be4a869e9911a79c20737119290fadbb9e60c4b9bac95499
BLAKE2b-256 checksum
How to use checksums
af4c7979a99f72dd0919a661e25926b944275c6418676cf60f2866b17579fd3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 17, 2026.

Transparency log

Release files / vcti_fileloader_json-1.0.3-py3-none-any.whl

Download URL vcti_fileloader_json-1.0.3-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b9746e18977bd005d22985c2d98cfb2efbdc4cb59958bf58aa586a6f9076249
BLAKE2b-256 checksum
How to use checksums
e88a285b24754a37e2c922a8fb02c534bf48d4b73410e2b25db0dc630f898df1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page