Registry / serialization / python-json-config

python-json-config

JSON →
library1.2.3pypypi✓ verified 24d ago

This library (version 1.2.3) provides a convenient way to load JSON configuration files, allowing access to values using dot notation (e.g., `config.server.port`). It also includes features for validating config field types and values, and transforming fields. The library's last update was in November 2019, indicating a maintenance-only or inactive release cadence.

pip install python-json-config
INSTALL
IMPORT
SIG · PYTHON-JSON-CONFIG
P
python-json-config
serializationpythonv1.2.3
Install
2.6s avg
Import
254ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.262s · 22.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.6s · import 0.246s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ConfigBuilder
from python_json_config import ConfigBuilder

This quickstart demonstrates how to initialize `ConfigBuilder`, parse a JSON configuration file, and access nested values using convenient dot notation. It also includes an example of validating field types and how environment variables can be used for configuration values.

import os import tempfile # Create a dummy config.json for the example config_content = ''' { "server": { "host": "localhost", "port": 8080 }, "database": { "name": "mydb", "user": "admin" }, "jwt_secret": "${JWT_SECRET:-default_secret_key}" } ''' with tempfile.TemporaryDirectory() as tmpdir: config_path = os.path.join(tmpdir, 'config.json') with open(config_path, 'w') as f: f.write(config_content) # Set an environment variable to demonstrate its use os.environ['JWT_SECRET'] = 'my_super_secret_jwt_key' from python_json_config import ConfigBuilder # Create config parser builder = ConfigBuilder() # Parse config from the temporary file config = builder.parse_config(config_path) # Access elements using dot notation host = config.server.host port = config.server.port db_name = config.database.name jwt_secret = config.jwt_secret # This will pick up from os.environ print(f"Server Host: {host}") print(f"Server Port: {port}") print(f"Database Name: {db_name}") print(f"JWT Secret: {jwt_secret}") # Validate field types builder.validate_field_type('server.port', int) builder.validate_field_type('database.user', str) print("Configuration fields validated successfully.") # Clean up environment variable del os.environ['JWT_SECRET']
Debug
Known issues
gotchaWhen serializing a `Config` object to JSON or msgpack, non-serializable Python objects (e.g., `datetime` objects) will be stringified. This can lead to loss of original data type upon deserialization if not explicitly handled.
fix
Implement custom serialization/deserialization logic for non-standard types if strict type preservation is required.
affects: <=1.2.3
gotchaThe `python-json-config` library has not seen updates since November 2019 (version 1.2.3). This indicates a lack of active development, which might mean no new features, limited official support for newer Python versions beyond 3.6, or unaddressed bugs/security concerns. Users should be aware of its maintenance status.
fix
Consider evaluating alternatives if active development, feature updates, or support for the latest Python versions are critical for your project.
affects: All versions
gotchaStandard JSON format does not officially support comments. While the library parses JSON, including comments in your `.json` configuration files will result in parsing errors (e.g., `json.decoder.JSONDecodeError`).
fix
Remove comments from JSON configuration files or preprocess them before parsing with `python-json-config`. For configuration that requires comments, consider formats like YAML or TOML.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'json_config'
The 'python-json-config' library is either not installed in your environment or its 'Config' class is imported incorrectly.
fix
Install the library using `pip install python-json-config` and then import the 'Config' class correctly with `from json_config import Config`.
FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
The path provided to the `Config` constructor for your JSON configuration file is incorrect or the file does not exist at the specified location.
fix
Verify that the configuration file exists at the given path and ensure the path is correct relative to where your script is being executed.
AttributeError: 'Config' object has no attribute 'your_field_name'
You are attempting to access a configuration field using dot notation (e.g., `config.your_field_name`) that is not present in the loaded JSON configuration data.
fix
Ensure the field name is spelled correctly and exists in your JSON configuration file, or handle its potential absence by checking its existence before access.
TypeError: 'field_name' field has invalid type '<class 'str'>'. Expected type: '<class 'int'>'
A value in your JSON configuration file does not match the expected data type defined in the associated configuration specification file (e.g., expecting an integer but receiving a string).
fix
Adjust the value in your JSON configuration file to match the expected data type, or update the type definition in your configuration specification if it is incorrect.
Upgrade
Version history
1.2.3latest on PyPI · released Nov 21, 2019
Audit
Dependencies
pythonrequiredRequired for the library to run.
Agent activity
5 hits · last 30 days
node
4
Resources
python-json-config — pip install python-json-config · libregistry