Skip to main content

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

  • #include directives — import other JX files with optional path extraction and aliasing: #include "other.jx"[a.b.c] as alias
  • Math constantspi, e, tau built in
  • Static globalstrue, false, null, nan, inf, -inf
  • All math module functions — plus max, 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:

  1. Comments// to end of line
  2. Trailing commas{"a": 1,} and [1, 2,] are legal
  3. 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)

Source distribution for jxconfig 0.1.0
File Size Uploaded
jxconfig-0.1.0.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jxconfig 0.1.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.0 This release

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