Skip to main content

JX — JSON eXtended: a minimal JSON-compatible config language with comments, trailing commas, and expressions

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jxconfig-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jxconfig-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file jxconfig-0.1.0.tar.gz.

File metadata

  • Download URL: jxconfig-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for jxconfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 737e5eb37718e551bb5edbf5f685f844c9bb12d03ca3760fad214b6eb0f664e5
MD5 576c43a6838f56d0413cffbb0a69d5b5
BLAKE2b-256 ae5a84a91a5c3708c6b93139a1198955d72fe57be5fe8738413e373a45cf0483

See more details on using hashes here.

File details

Details for the file jxconfig-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: jxconfig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for jxconfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bde06d1f9aec6118bfc9868b017d06eb80465b039cc7d9f9f6d57d26d86757f1
MD5 1f279a844b8ec70345f2389402778ec8
BLAKE2b-256 52d50340d1dab5376777d2428d5f4adfb58d9d86978b2bb8f3171b8d7f55a59d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page