JX — JSON eXtended
A minimal, deterministic JSON-compatible configuration language with three deliberate extensions. JX is a lightweight preprocessor for configuration files — not a general-purpose programming language.
Features
| Extension | Description |
|---|---|
| Inline comments | // single-line comments (block comments intentionally excluded) |
| Trailing commas | Allowed in objects and arrays; stripped before JSON parsing |
| Numeric expressions | Object keys define variables; reference them with ${name}; supports + - * / ( ) |
Beyond the basics
#includedirectives — import other JX files with optional path extraction and aliasing:#include "other.jx"[a.b.c] as alias- Math constants —
pi,e,taubuilt in - Static globals —
true,false,null,nan,inf,-inf - All
mathmodule functions — plusmax,min,round,abs - Nested scopes — inner objects shadow outer keys; evaluation is single-pass and order-dependent
Installation
pip install jxconfig
Or from source:
pip install git+https://github.com/KrisTHL181/jxconfig.git
Quick Start
from jxconfig import load_jx
# Load from a string
config = load_jx('''
{
// server configuration
base_port: 8000,
workers: 4,
total_ports: base_port + workers, // 8004
pi_area: 3 * pi * 2 ** 2, // math constants
}
''')
print(config["total_ports"]) # 8004
Including other files
db.jx:
{
host: "localhost",
port: 5432,
}
app.jx:
{
#include "db.jx"[host, port] as db
name: "myapp",
connection: "${db.host}:${db.port}",
}
From a file
from jxconfig import load_jx
with open("config.jx") as f:
config = load_jx(f.read(), current_dir="configs/")
# All top-level keys are accessible by name
print(config["name"])
Language Spec
JX files are valid JSON with three relaxations:
- Comments —
//to end of line - Trailing commas —
{"a": 1,}and[1, 2,]are legal - Unquoted expression values — after
:, an expression may be written without quotes; variables are interpolated with${name}
Expressions support the standard arithmetic operators (+, -, *, /,
parentheses) plus all Python math module functions and constants.
API
load_jx(text: str, current_dir: str = ".") -> dict
Parse and evaluate a JX string. current_dir sets the base directory for
resolving relative #include paths.
evaluate(value, scope: dict) -> Any
Recursively evaluate expressions in a parsed JSON structure.
eval_expression(expr: str, scope: dict) -> Any
Evaluate a single expression string against a variable scope.
process_directives(text: str, current_dir: str, seen_files: set) -> tuple[str, dict]
Pre-process #include directives before JSON parsing.
License
MIT
Release files for jxconfig 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jxconfig-0.1.0.tar.gz | 10.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jxconfig-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / jxconfig-0.1.0.tar.gz
| Download URL | jxconfig-0.1.0.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
737e5eb37718e551bb5edbf5f685f844c9bb12d03ca3760fad214b6eb0f664e5
|
|
BLAKE2b-256 checksum How to use checksums |
ae5a84a91a5c3708c6b93139a1198955d72fe57be5fe8738413e373a45cf0483
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Release files / jxconfig-0.1.0-py3-none-any.whl
| Download URL | jxconfig-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bde06d1f9aec6118bfc9868b017d06eb80465b039cc7d9f9f6d57d26d86757f1
|
|
BLAKE2b-256 checksum How to use checksums |
52d50340d1dab5376777d2428d5f4adfb58d9d86978b2bb8f3171b8d7f55a59d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|