Rust-powered JSON merging with custom modifiers
Project description
JSON Multi Merge
A high-performance JSON merging library powered by Rust, featuring advanced merge rules and key modifiers.
Features
- Recursive Object Merging: Deep merge nested JSON objects
- Array Replacement: Second object's arrays take precedence
- Key Modifiers:
key!- Replace value instead of mergingkey--- Remove this key from the resultkey-history- Append list value instead of replacing
- Type Conflict Resolution: Last object's type wins
- Null Handling: Treat null as a regular value
- High Performance: Rust backend for efficient deep merges
Installation
pip install json-multi-merge
Usage
Variadic Input
The merge function now accepts any number of dictionary arguments:
# Single dictionary
merge({"a": 1})
# Multiple dictionaries
merge({"a": 1}, {"b": 2}, {"c": 3})
# From a list (using unpacking)
dicts = [{"a": 1}, {"b": 2}]
merge(*dicts)
# Invalid usage (will raise TypeError)
merge({"a": 1}, [1, 2, 3]) # Second item is not a dict
merge("not a list") # Not a list at all
Basic Merge
from json_multi_merge import merge
a = {"name": "Alice", "age": 30}
b = {"age": 31, "city": "Paris"}
result = merge(a, b)
# {'name': 'Alice', 'age': 31, 'city': 'Paris'}
Nested Object Merging
base = {
"user": {
"name": "Alice",
"contact": {"email": "alice@example.com"}
}
}
update = {
"user": {
"contact": {"phone": "555-1234"},
"preferences": {"theme": "dark"}
}
}
result = merge(base, update)
# {
# "user": {
# "name": "Alice",
# "contact": {"email": "alice@example.com", "phone": "555-1234"},
# "preferences": {"theme": "dark"}
# }
# }
Merging Multiple Objects
Merge any number of JSON objects sequentially:
result = merge(
{"base": 1},
{"base": 2, "new!": "value"},
{"base--": None, "final": True}
)
# Result: {'new': 'value', 'final': True}
Batch Processing Example
configs = [
{"defaults": {"timeout": 30}},
{"defaults": {"retries": 3}},
{"defaults!": {"cache": "enabled"}},
{"defaults--": {}, "environment": "prod"}
]
final_config = merge(*configs)
# Result: {'environment': 'prod'}
Array Replacement
base = {"tags": ["old"], "items": [1, 2]}
update = {"tags": ["new"], "items!": [3, 4]}
result = merge(base, update)
# {"tags": ["new"], "items": [3, 4]}
Key Modifiers
Replace (!) and Omit (--)
config = {
"debug": True,
"plugins": ["basic"],
"temp_data": {"key": "value"}
}
update = {
"debug!": False,
"plugins--": None,
"temp_data--": {"key": "value"}
}
result = merge(config, update)
# {"debug": False}
Deeply Nested Modifiers
base = {
"system": {
"settings": {
"logging": {"level": "info"},
"backups": {"enabled": False}
}
}
}
update = {
"system!": {
"settings--": {"logging": {"level": "info"}},
"new_settings": {"cache_size": "256MB"}
}
}
result = merge(base, update)
# {
# "system": {
# "new_settings": {"cache_size": "256MB"}
# }
# }
Type Conflicts
base = {"data": {"values": [1, 2, 3]}}
update = {"data": "invalid"}
result = merge(base, update)
# {"data": "invalid"}
Null Handling
base = {"user": None}
update = {"user!": {"name": "Bob"}}
result = merge(base, update)
# {"user": {"name": "Bob"}}
API Reference
merge(base: dict, update: dict) -> dict
Merges two JSON objects according to the rules:
- Objects are merged recursively
- Arrays are replaced
- Key modifiers change merge behavior:
key!: Replace value completelykey--: Remove key from result
- Last object's value type wins in conflicts
Performance
The Rust implementation provides significant performance benefits for:
- Large JSON documents (10k+ elements)
- Deeply nested structures (10+ levels)
- Batch processing operations
# Benchmark example (1k nested objects)
import timeit
setup = '''
import json_multi_merge
base = {"data": {"nested": {"value": 1}}}
update = {"data": {"nested": {"value!": 2}}}
'''
print(timeit.timeit('json_multi_merge.merge(base, update)', setup, number=10000))
# Typical result: ~0.8 seconds (vs ~4.2 seconds for pure Python equivalent)
License
MIT License - See LICENSE for details.
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file json_multi_merge-0.3.1.tar.gz.
File metadata
- Download URL: json_multi_merge-0.3.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ab00d004379f946bd1ea439da7c50bdf24009e3dc8c7c6bf75970fd41fd0d3e
|
|
| MD5 |
d481a31d4d30e4d5b8d98a3c1d7e3331
|
|
| BLAKE2b-256 |
3c5afef4e865babf6abfc09c21b6cdfa106ec25dbf1f5dd0230f2b525b9ea8c4
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-win_amd64.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-win_amd64.whl
- Upload date:
- Size: 122.2 kB
- Tags: CPython 3.7+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d129790eec8b14b1f38093bd30a07a2e446d80c962f67c228d0575ae7b1b055
|
|
| MD5 |
bbddb70efa7258048f1bb877e16ff46f
|
|
| BLAKE2b-256 |
fc7e0c2298266a4b6ce4744d4ec9fd55997df1e81cd463ef0391b43ff5547e73
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-win32.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-win32.whl
- Upload date:
- Size: 115.8 kB
- Tags: CPython 3.7+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9dbda2d5086acd1731f15443b9edfc4277f1138c1ef3c6f15c739c9d4a1124d
|
|
| MD5 |
130d1dd5893bb3db9151ac4cd0165500
|
|
| BLAKE2b-256 |
6300b91141ccc5b146277a8444559d8f9b68e620c6360221f899f04146160e33
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 429.0 kB
- Tags: CPython 3.7+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8df2e1b34d2fe1bc896d8efb641f98ba7f488364766e637a6020f9ab159ce55
|
|
| MD5 |
4f242c145c113f9ca4145e4e4ad93b76
|
|
| BLAKE2b-256 |
52af06e4735488fc33f61a7d2a644209c8399e666819454661c8105c86feaad4
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-musllinux_1_2_i686.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-musllinux_1_2_i686.whl
- Upload date:
- Size: 451.4 kB
- Tags: CPython 3.7+, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b0fbdc72c4049daf5e481b3eb0637d2eead2930a0b9f8c4ed90e321f3db9426
|
|
| MD5 |
ead516cf67b9baa9f7c17d76bf917af9
|
|
| BLAKE2b-256 |
51047f76adf959e98f559ef97265ccf85e029331dec222daee84e6f3b36da52d
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-musllinux_1_2_armv7l.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-musllinux_1_2_armv7l.whl
- Upload date:
- Size: 524.5 kB
- Tags: CPython 3.7+, musllinux: musl 1.2+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a46bd79b4c0112dbd1e1535c8cd0abb9478b63b1cf0fe009e95b85f220e4417
|
|
| MD5 |
3356f4b1979918f8086d22d5d943ed5e
|
|
| BLAKE2b-256 |
90a8fc7cdb9430a4c6da98c4c89a37672a0380c6a4590f82f0b8ad930421c240
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 432.4 kB
- Tags: CPython 3.7+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
097d7eae4bcbdab2e8799f610f3d89a8c81da711794f5d6906818af8c3a64b03
|
|
| MD5 |
79731f1aff3eb7b102a6b9dccf0edab5
|
|
| BLAKE2b-256 |
1a8ff77cc73441db9c16842d7c1b63d95c46ef4e214c330c338366dde3f6b146
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 258.5 kB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e779de1f0b3e1a4e2bb3fb1602bb0c9629dc9f728528459f26936052647d3694
|
|
| MD5 |
a1a8bee3b08f6823bb13d0094d319318
|
|
| BLAKE2b-256 |
057d9466c8204899dd54a830474c87df3dbb8dd26828a53bbf37cb0358473105
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 262.0 kB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
783b844e15e09f07101bdcfc506813bd73192636a9f21ef4a537ef72ea18a38a
|
|
| MD5 |
be73b6f6e460b8d926e49dc72ba25f90
|
|
| BLAKE2b-256 |
5a2e679ccc396788aeb3e07a054ff0d83aa7a6720e4d14b6bd79e5506f78d07c
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 254.3 kB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85d8d87e3b963a6a58f2df360ef98da84d07a18c8125e4b60986fab177896b7f
|
|
| MD5 |
6db3e059d3e1d54f313697dcdbe7d5f4
|
|
| BLAKE2b-256 |
7b716ce532b199411a39e7290307e9c85d5d8c281d9f1cad56a4a482ebcf74b1
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 271.3 kB
- Tags: CPython 3.7+, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c2306a83d3a00238b5de2a471ca6ecbee7de5617924452d7c95bbaf94b48f24
|
|
| MD5 |
41686554a81a1dd84be1a28b1634a199
|
|
| BLAKE2b-256 |
8614e171e8e50704187c64d71ba0a7cf55a645dfe984dc041246f66a3fefe6d4
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 224.7 kB
- Tags: CPython 3.7+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
207db64ab226c08cc4fd433bfb3a233476512fac2d73bb4bc09efe513a91e586
|
|
| MD5 |
526b36d9f8ea71c9e9ddd76fe1ae1998
|
|
| BLAKE2b-256 |
71b2a14d0c27a7a25c0e8a3e34cb55bc568ed22b8a842765de14a579b96b952d
|
File details
Details for the file json_multi_merge-0.3.1-cp37-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: json_multi_merge-0.3.1-cp37-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 231.0 kB
- Tags: CPython 3.7+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f78c5c7e2b4ab0c91ee393965cba8795239590762f3875eaa62b38c9819dbc5d
|
|
| MD5 |
0ac48a6d88addaded391fef06a1ed4e3
|
|
| BLAKE2b-256 |
2a4cdb26106daf340e5e78e771e5c0ba3b3844a8b0aeb7dfb73f7cee67ad7518
|