Skip to main content

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 merging
    • key-- - Remove this key from the result
  • 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:

  1. Objects are merged recursively
  2. Arrays are replaced
  3. Key modifiers change merge behavior:
    • key!: Replace value completely
    • key--: Remove key from result
  4. 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

json_multi_merge-0.2.4.tar.gz (9.6 kB view details)

Uploaded Source

Built Distributions

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

json_multi_merge-0.2.4-cp37-abi3-win_amd64.whl (120.3 kB view details)

Uploaded CPython 3.7+Windows x86-64

json_multi_merge-0.2.4-cp37-abi3-win32.whl (114.1 kB view details)

Uploaded CPython 3.7+Windows x86

json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_x86_64.whl (422.7 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ x86-64

json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_i686.whl (443.9 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ i686

json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_armv7l.whl (517.3 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ ARMv7l

json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_aarch64.whl (425.9 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ ARM64

json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (256.0 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (259.3 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARMv7l

json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (252.1 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

json_multi_merge-0.2.4-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (267.4 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.5+ i686

json_multi_merge-0.2.4-cp37-abi3-macosx_11_0_arm64.whl (223.7 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

json_multi_merge-0.2.4-cp37-abi3-macosx_10_12_x86_64.whl (228.8 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file json_multi_merge-0.2.4.tar.gz.

File metadata

  • Download URL: json_multi_merge-0.2.4.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.1

File hashes

Hashes for json_multi_merge-0.2.4.tar.gz
Algorithm Hash digest
SHA256 bdaf2d1a1036d13ded8ad98f98c59246df3345459d57898ee979d5278cc47c7e
MD5 fb5b500f8a39d6792023ab7426614f5b
BLAKE2b-256 cc9e208e19a10c731cd5046b8862f0dd5f383f26f909b8198986d9e17d66f663

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 932c1d41df4520de70e72caffb1a8c2c5a3b76962f2b8c760251503e7999c729
MD5 06b77a71e654020b1e76506d252b4776
BLAKE2b-256 daa2466c96bb735b8615d567605c13b951c39648d60974d5a501a5f3514d1825

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-win32.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 0803056966770fb76f417aaf7b27f08b523c121135c86bc1b2819d82c8f0b4d4
MD5 4054f03bf8fec00041e26cf8c6ee74ca
BLAKE2b-256 da67df173ec2b7c843865adb33e55a6455b5b99727dbccad862d3e3f492f06fc

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 33735aa205526a892b29d07af343cbf171c39fd3918a26c6f57a426f4cfffe4b
MD5 a3e73f2e370b3b549ff34a6b7af3409f
BLAKE2b-256 922bbf21369ba1f6d595d252f80a19ac0fb8383dcc68e3d02aac4a7c89d15f5f

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 b46b03cfa2a3ed25d1f4460eba49e6a6c9188216c74fba7774428b35328c6e56
MD5 227aff4b4302370508dae30efd45bc9e
BLAKE2b-256 2278f824fa70f3af241d41772647c5e4a5920bf25fa124e5e7e2422549b62849

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 e9e5048dd70f336a67c8a37a39ee60e1b646503f92639ef17635422b3ec41621
MD5 7c669c78fd6b47a960364536ccb764b0
BLAKE2b-256 fca4af4c4f24e92ac2564a911d551173eb605feb3e45ae6d5c7c8ecb3047bcde

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 9aad572a3b1695e0229491ea11bf91d3accc822df3b98a79c7aa4f69e70a9f96
MD5 91ee0ddf4ec4a9a0291bfc570b51d462
BLAKE2b-256 d6f25e18b618a65e2cd224d15dc6bad7af5b3d859697519059d916a21dfcbe52

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 253ca6445aaa23ac166bbf7ecbaef40a637f8c4b164825ec322709df646d50ca
MD5 d031b5224213e0fa8eb3b0f8b3820983
BLAKE2b-256 f4cb16ed410fb7ac8c1e8dd50d32e66dfa0abab3404f39684d2968a4055c13de

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1b080940b793e552a648ca76b1fa5a345d4457754459e8649fb8df872d93b5fb
MD5 9e3e32a169eaa206e7b14cd92a3048ef
BLAKE2b-256 39e6428940f5370dcd0d11493eb2cf9db8d886470db69986ed98e569e225e6dc

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b99aa9765c3d461fa8124e439e388e0a98a3356c7a08c9ff02c9abdb1a930266
MD5 b8d83887869a8b0ed1fdb07f61a02944
BLAKE2b-256 2efe5934cac31f1b99775b45bb3d9bfacab0a1c54326bc89620de93ef7d53477

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 aeb68d0bdba387c4d579e33d4d1742d9bde4556dbc32a49b8e248924a9866681
MD5 d08450897ae64d5335da98f9100d12a2
BLAKE2b-256 6a9a7a2846a88a33b7a12e071de8db44a6dbdba07cecf9279603db25949b1c37

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 96ba3f9da7387fc5f91f7f2c73a399728e8263d86c70b157b1b613f16d0085cc
MD5 ff3c3ac5849eb4ab9e657aee796eeeb8
BLAKE2b-256 282090b5c6aff13200df0c52676c58060a3aa34986390eedd462b019f75927ba

See more details on using hashes here.

File details

Details for the file json_multi_merge-0.2.4-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for json_multi_merge-0.2.4-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4ceda2335db6b866804a510c453a9b2743287a3eba4c1e6f4a414d5f212b0883
MD5 a76f2eb64384a61f7fa2eb8daefd4cc9
BLAKE2b-256 ec16483fbf09ee4575870fa765ba28009d85e0967d7b6aa9b9467e16cf770023

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