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
    • key-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:

  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.3.0.tar.gz (10.0 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.3.0-cp37-abi3-win_amd64.whl (122.5 kB view details)

Uploaded CPython 3.7+Windows x86-64

json_multi_merge-0.3.0-cp37-abi3-win32.whl (116.1 kB view details)

Uploaded CPython 3.7+Windows x86

json_multi_merge-0.3.0-cp37-abi3-musllinux_1_2_x86_64.whl (429.4 kB view details)

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

json_multi_merge-0.3.0-cp37-abi3-musllinux_1_2_i686.whl (451.6 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ i686

json_multi_merge-0.3.0-cp37-abi3-musllinux_1_2_armv7l.whl (524.9 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ ARMv7l

json_multi_merge-0.3.0-cp37-abi3-musllinux_1_2_aarch64.whl (432.5 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ ARM64

json_multi_merge-0.3.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (258.9 kB view details)

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

json_multi_merge-0.3.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (262.3 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARMv7l

json_multi_merge-0.3.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (254.6 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

json_multi_merge-0.3.0-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (271.6 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.5+ i686

json_multi_merge-0.3.0-cp37-abi3-macosx_11_0_arm64.whl (224.9 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

json_multi_merge-0.3.0-cp37-abi3-macosx_10_12_x86_64.whl (231.3 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for json_multi_merge-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4135c24db58eb6cdc949de4f87cc2fc95c546f69d28125e422ef5e7e7f623325
MD5 4846517423eba1aa8339ee5c3cc37284
BLAKE2b-256 f0542ba34a0eac7b044f0e738d6737a926c16a86c05057b97243d0c0acf3644b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 73ed642a940f608af68559a9420d9752c8d373b016a82ad4d09e3d00723c591d
MD5 52fb0d4725634c3909ae03cc529ced29
BLAKE2b-256 0d00ddb61b46d6a95ee85bd74e3dfe3b3105a8ece767a46389cf37309b2875be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 a81e485ed7caa6c57b2da3d95e63ed5939f31cfa376029ffd9ee50f1c1053f48
MD5 bcbf986ab4e77ae4561c8f693d18f0ad
BLAKE2b-256 548c05156e74c07d9fbea9e8559cf12004537cd2a7cbf9ec8c53622076270b54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 924d374702c750458c1b50d2928c861464fd7f3a2be363db6e403c9dfbe2c6b1
MD5 8be11dd67cde14d57c2aa0b02d1135e2
BLAKE2b-256 7546bddaed3abdccd3d23d66fe951da9f6d7f19efdda454ef6c6f56c46d33997

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 f4f59ef00f3482a3a446d70b9409fa8c3bad8569a202db690a3191422843c16d
MD5 bb2f6b0ce5a2b546a0bd13ff8d883ded
BLAKE2b-256 9c81262aa08b99d64bba310a547a53f8db0674c02cc681a7a1982d60076eefad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 7c7c47ba139236091b4e350d9068ff59b12bf6eb47f84af78e8daee3ecd9c82e
MD5 1065f1cf3e43e4791a5f484295ddc10c
BLAKE2b-256 8317ca593e40dc9dc6fce96d112b844e60ff3ad8429a8f4647acc542d016882d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 1777926d1aadfa12427d1a22f852f7623ade7efdaa17cad1cda55d38fb0f819e
MD5 52cef666039044bc8ca2564fa832447e
BLAKE2b-256 0a56c182b7bfb0fe8e1d0f233d2e8089befe8b379fa0a1446aec6f184b9718b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 00aa8b03467c3ac70897436da36aee63568066413b07a61dd6941143f2e56b4d
MD5 53f28a52c9e43b45f86154e89fc10965
BLAKE2b-256 031cddc4f9b1ae28a90efc40b82e140a110ecf1852af269944f3699f8ca05b21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 b93426124d3f85a72f11f53e3c96f7399cd8c5278dfb13d610fdf3ee6e1a042d
MD5 ad4a66cfa9b530dc20e5976f89b14f1f
BLAKE2b-256 63fa31cd2d84d25277951e581e13aa48b45c94be3962e74a8c16de7ad662ed2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8e272d433aa6ca08b0e56372d03a6fe23f0694a70331babcf89f17a25a44442a
MD5 5cdf31c65a7ee6c849b68bd11ea256d8
BLAKE2b-256 9ae06617da0caff62114f7c3c730dc509a1e21d7edd5d69eb9a8da35a6c4a690

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 6f4302b254f0c470bea1ba624147ae759ba4a7aff2201ef2896e8b3490a0949c
MD5 190180c66760e8460948ddcd369d7bcf
BLAKE2b-256 219c62f75fec777d8d99ce0b7baee23f1d796b225dba7f32cca376a2ced03819

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7fda5bd4499806b1541cb5e24295ea0c3f2a12f900efbe2e7dbba4b9f91b9da6
MD5 9600b23b3a0f7c73fc3b88eee0b2d53e
BLAKE2b-256 15068e6f3480483b5ce2425a2ff0ba1b10b17172fa21b7661f3194aaa00ff666

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_multi_merge-0.3.0-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5afbfa47c9caac936eb3511ba770f8f6a1025598a83c8c9fe40629bd63a75f4b
MD5 b3f5fe1639759a493a3a7e1af4ae9992
BLAKE2b-256 9c4b0c9803cd4fe819721f4782e2f09f79271ffb316f567abc4ea7c0bcd7c059

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