Merge JSON configuration objects with explicit replacement rules
Python
Apply a recursive JSON object overlay while replacing whole arrays and preserving null as a value.
Use this small CLI to combine a base configuration with an explicit override object. Corresponding objects merge recursively; every other overlay value replaces the base value. Arrays are replaced as a whole. The command reads its request from stdin and returns the result without changing source files.
Before you start
Python 3.12 standard library and the reviewed pinned runtime; no third-party packages.
One UTF-8 JSON request on stdin, at most 20000 encoded bytes. One extra byte may be read to detect overflow.
Use synthetic examples when sharing requests. The program does not read configuration files, environment variables or network services.
Build and check
Save the downloaded source as merge-json-configuration-python.py.
Save the example JSON request below as request.json.
Run python3 merge-json-configuration-python.py < request.json.
Compare stdout with the expected JSON. Exit 0 processes a valid request; invalid input exits 2 with empty stdout and a generic stderr message.
Limits to understand
The request must have exactly base and overlay, both objects. Maximum nesting is 64 open objects or arrays, counting the outer request object as level one.
Only corresponding objects merge recursively. Arrays, booleans, numbers and null replace prior values. Null is not a deletion marker; this custom policy differs from JSON Merge Patch (RFC 7396).
Duplicate keys, non-finite numbers and unpaired Unicode surrogates are rejected. Integers retain precision within the input byte bound; fractional and exponent-form values use Python floating-point precision.
The program explicitly disables the Python integer digit-conversion limit inside its isolated process; request size and sandbox resource limits still apply.
This does not validate an application schema, substitute environment variables, redact secrets or preserve whitespace, numeric spelling and original object key order.
Code license: MIT. Keep the license notice with your copy.
Example version 1.0.0 · Documentation reviewed 2026-11-14.
32 independent CLI cases passed in rootless Docker on the pinned Python 3.12 image, with 512 MiB RAM, 1 CPU and no network. Includes the documented example, malformed input, Unicode and the inclusive 20000-byte boundary. Other runtimes and all possible inputs have not been verified.