fastjsondiff


Namefastjsondiff JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryFast JSON difference detection library with path-based filtering
upload_time2025-08-21 05:13:19
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords json diff comparison rust fast performance
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastJSONDiff

A high-performance JSON difference detection library implemented in Rust with Python bindings. FastJSONDiff provides fast, memory-efficient JSON comparison with support for path-based filtering.

## Features

- ⚡ **High Performance**: Implemented in Rust for maximum speed
- 🔍 **Path-based Filtering**: Use `ignore` and `allow` parameters to control which parts of JSON are compared
- 🛠 **Flexible Path Notation**: Support for both dot notation (`"args.field"`) and slash notation (`"args/field"`)
- 📦 **Easy Installation**: Simple pip install with pre-compiled wheels
- 🐍 **Python Native**: Seamless Python integration with full type hints

## Installation

```bash
pip install fastjsondiff
```

## Quick Start

```python
import fastjsondiff

# Basic comparison
json1 = {"a": 1, "b": {"c": 2}}
json2 = {"a": 1, "b": {"c": 3}}

differences = fastjsondiff.compare_json(json1, json2)
print(differences)
# Output: ['Value mismatch at b/c: Number(2) vs Number(3)']

# Using ignore to skip certain paths
differences = fastjsondiff.compare_json(json1, json2, ignore=["b"])
print(differences)
# Output: []

# Using allow to only compare specific paths
differences = fastjsondiff.compare_json(json1, json2, allow=["b/c"])
print(differences)
# Output: ['Value mismatch at b/c: Number(2) vs Number(3)']
```

## API Reference

### `compare_json(j1, j2, ignore=None, allow=None)`

Compare two JSON objects and return a list of differences.

#### Parameters

- **j1**: The first JSON object to compare. Can be a dict, list, or any JSON-serializable object.
- **j2**: The second JSON object to compare. Can be a dict, list, or any JSON-serializable object.
- **ignore** (optional): List of paths to ignore during comparison. Paths can use either dot notation (e.g., `"args.field"`) or slash notation (e.g., `"args/field"`). If a path is in the ignore list, it and all its children will be skipped.
- **allow** (optional): List of paths to include in comparison. If provided, only paths that match the allow list (or are parent paths of allowed paths) will be compared. Paths can use either dot notation (e.g., `"args.field"`) or slash notation (e.g., `"args/field"`). If allow is empty or None, all paths are compared (except those in ignore).

#### Returns

A list of strings describing the differences found. Each string describes a specific difference, such as:

- `"Value mismatch at path: value1 vs value2"`
- `"Missing key in second JSON: path"`

#### Raises

- **ValueError**: If the input objects cannot be converted to JSON.

## Advanced Examples

### Complex JSON Comparison

```python
import fastjsondiff

# Complex nested JSON objects
json1 = {
    "name": "create_testbench_for_current_mirror",
    "args": {
        "netlist_name": "001_02_0.txt",
        "current_mirror_name": "current_mirror_2",
        "testbench_description": "Testbench for impedance analysis of modified current mirror 2",
        "ac_analysis_settings": {
            "start_freq": 10000,
            "stop_freq": 10000000,
            "steps": 3,
            "step_type": "dec",
        },
        "voltage_source_settings": {
            "power_supply_voltage": 1.8,
            "bias_current": 1e-5,
            "primary_cascode_ac_stimulus": 1,
        },
    },
    "id": "call_jBf9Gg0IQQj0XSTVnZVyO16p",
    "type": "tool_call",
}

json2 = {
    "name": "create_testbench_for_current_mirror",
    "args": {
        "netlist_name": "001_02_0.txt",
        "current_mirror_name": "current_mirror_2",
        "testbench_description": "Testbench for AC impedance analysis of current_mirror_2 (10kHz to 10MHz)",
        "ac_analysis_settings": {
            "start_freq": 10000.0,
            "stop_freq": 10000000.0,
            "steps": 3,
            "step_type": "dec",
        },
        "voltage_source_settings": {
            "power_supply_voltage": 1.8,
            "bias_current": 1e-5,
            "primary_cascode_ac_stimulus": 1.0,
        },
    },
    "id": "chatcmpl-tool-924103cb3ed2478990fbd41d341355e6",
    "type": "tool_call",
}

# Compare only specific paths
differences = fastjsondiff.compare_json(
    json1,
    json2,
    allow=[
        "args/netlist_name",
        "args/current_mirror_name",
        "args/ac_analysis_settings/start_freq",
        "args/ac_analysis_settings/stop_freq",
        "args/testbench_description",
        "args/voltage_source_settings",
    ],
)

print("Differences found:", differences)
# Output: Differences found: ['Value mismatch at args/testbench_description: String("Testbench for impedance analysis of modified current mirror 2") vs String("Testbench for AC impedance analysis of current_mirror_2 (10kHz to 10MHz)")', 'Value mismatch at args/ac_analysis_settings/start_freq: Number(10000) vs Number(10000.0)', 'Value mismatch at args/ac_analysis_settings/stop_freq: Number(10000000) vs Number(10000000.0)', 'Value mismatch at args/voltage_source_settings/primary_cascode_ac_stimulus: Number(1) vs Number(1.0)']
```

### Using Dot Notation

```python
# Dot notation works the same as slash notation
differences = fastjsondiff.compare_json(
    json1,
    json2,
    allow=["args.testbench_description", "args.voltage_source_settings"]
)
```

### Ignoring Specific Paths

```python
# Ignore the id field and all voltage source settings
differences = fastjsondiff.compare_json(
    json1,
    json2,
    ignore=["id", "args/voltage_source_settings"]
)
```

## Performance

FastJSONDiff is designed for high performance:

- **Rust Implementation**: Core logic is implemented in Rust for maximum speed
- **Memory Efficient**: Minimal memory allocation during comparison
- **Optimized Path Matching**: Efficient path matching algorithms for filtering

## Development

### Building from Source

```bash
# Clone the repository
git clone https://github.com/yourusername/fastjsondiff.git
cd fastjsondiff

# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install maturin
pip install maturin

# Build and install in development mode
maturin develop
```

### Running Tests

```bash
# Run the test suite
python test_fastjsondiff.py
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Changelog

### 0.1.0

- Initial release
- Basic JSON comparison functionality
- Path-based filtering with ignore and allow parameters
- Support for both dot and slash notation in paths


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastjsondiff",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Karthik M Prakash <mkarthikprakash.work@gmail.com>",
    "keywords": "json, diff, comparison, rust, fast, performance",
    "author": null,
    "author_email": "Karthik M Prakash <mkarthikprakash.work@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/76/5b/cde0ccd511690cd8f4b90d0da54f2ab66f133167e21abf4f9c3fcfaea3c8/fastjsondiff-0.1.0.tar.gz",
    "platform": null,
    "description": "# FastJSONDiff\n\nA high-performance JSON difference detection library implemented in Rust with Python bindings. FastJSONDiff provides fast, memory-efficient JSON comparison with support for path-based filtering.\n\n## Features\n\n- \u26a1 **High Performance**: Implemented in Rust for maximum speed\n- \ud83d\udd0d **Path-based Filtering**: Use `ignore` and `allow` parameters to control which parts of JSON are compared\n- \ud83d\udee0 **Flexible Path Notation**: Support for both dot notation (`\"args.field\"`) and slash notation (`\"args/field\"`)\n- \ud83d\udce6 **Easy Installation**: Simple pip install with pre-compiled wheels\n- \ud83d\udc0d **Python Native**: Seamless Python integration with full type hints\n\n## Installation\n\n```bash\npip install fastjsondiff\n```\n\n## Quick Start\n\n```python\nimport fastjsondiff\n\n# Basic comparison\njson1 = {\"a\": 1, \"b\": {\"c\": 2}}\njson2 = {\"a\": 1, \"b\": {\"c\": 3}}\n\ndifferences = fastjsondiff.compare_json(json1, json2)\nprint(differences)\n# Output: ['Value mismatch at b/c: Number(2) vs Number(3)']\n\n# Using ignore to skip certain paths\ndifferences = fastjsondiff.compare_json(json1, json2, ignore=[\"b\"])\nprint(differences)\n# Output: []\n\n# Using allow to only compare specific paths\ndifferences = fastjsondiff.compare_json(json1, json2, allow=[\"b/c\"])\nprint(differences)\n# Output: ['Value mismatch at b/c: Number(2) vs Number(3)']\n```\n\n## API Reference\n\n### `compare_json(j1, j2, ignore=None, allow=None)`\n\nCompare two JSON objects and return a list of differences.\n\n#### Parameters\n\n- **j1**: The first JSON object to compare. Can be a dict, list, or any JSON-serializable object.\n- **j2**: The second JSON object to compare. Can be a dict, list, or any JSON-serializable object.\n- **ignore** (optional): List of paths to ignore during comparison. Paths can use either dot notation (e.g., `\"args.field\"`) or slash notation (e.g., `\"args/field\"`). If a path is in the ignore list, it and all its children will be skipped.\n- **allow** (optional): List of paths to include in comparison. If provided, only paths that match the allow list (or are parent paths of allowed paths) will be compared. Paths can use either dot notation (e.g., `\"args.field\"`) or slash notation (e.g., `\"args/field\"`). If allow is empty or None, all paths are compared (except those in ignore).\n\n#### Returns\n\nA list of strings describing the differences found. Each string describes a specific difference, such as:\n\n- `\"Value mismatch at path: value1 vs value2\"`\n- `\"Missing key in second JSON: path\"`\n\n#### Raises\n\n- **ValueError**: If the input objects cannot be converted to JSON.\n\n## Advanced Examples\n\n### Complex JSON Comparison\n\n```python\nimport fastjsondiff\n\n# Complex nested JSON objects\njson1 = {\n    \"name\": \"create_testbench_for_current_mirror\",\n    \"args\": {\n        \"netlist_name\": \"001_02_0.txt\",\n        \"current_mirror_name\": \"current_mirror_2\",\n        \"testbench_description\": \"Testbench for impedance analysis of modified current mirror 2\",\n        \"ac_analysis_settings\": {\n            \"start_freq\": 10000,\n            \"stop_freq\": 10000000,\n            \"steps\": 3,\n            \"step_type\": \"dec\",\n        },\n        \"voltage_source_settings\": {\n            \"power_supply_voltage\": 1.8,\n            \"bias_current\": 1e-5,\n            \"primary_cascode_ac_stimulus\": 1,\n        },\n    },\n    \"id\": \"call_jBf9Gg0IQQj0XSTVnZVyO16p\",\n    \"type\": \"tool_call\",\n}\n\njson2 = {\n    \"name\": \"create_testbench_for_current_mirror\",\n    \"args\": {\n        \"netlist_name\": \"001_02_0.txt\",\n        \"current_mirror_name\": \"current_mirror_2\",\n        \"testbench_description\": \"Testbench for AC impedance analysis of current_mirror_2 (10kHz to 10MHz)\",\n        \"ac_analysis_settings\": {\n            \"start_freq\": 10000.0,\n            \"stop_freq\": 10000000.0,\n            \"steps\": 3,\n            \"step_type\": \"dec\",\n        },\n        \"voltage_source_settings\": {\n            \"power_supply_voltage\": 1.8,\n            \"bias_current\": 1e-5,\n            \"primary_cascode_ac_stimulus\": 1.0,\n        },\n    },\n    \"id\": \"chatcmpl-tool-924103cb3ed2478990fbd41d341355e6\",\n    \"type\": \"tool_call\",\n}\n\n# Compare only specific paths\ndifferences = fastjsondiff.compare_json(\n    json1,\n    json2,\n    allow=[\n        \"args/netlist_name\",\n        \"args/current_mirror_name\",\n        \"args/ac_analysis_settings/start_freq\",\n        \"args/ac_analysis_settings/stop_freq\",\n        \"args/testbench_description\",\n        \"args/voltage_source_settings\",\n    ],\n)\n\nprint(\"Differences found:\", differences)\n# Output: Differences found: ['Value mismatch at args/testbench_description: String(\"Testbench for impedance analysis of modified current mirror 2\") vs String(\"Testbench for AC impedance analysis of current_mirror_2 (10kHz to 10MHz)\")', 'Value mismatch at args/ac_analysis_settings/start_freq: Number(10000) vs Number(10000.0)', 'Value mismatch at args/ac_analysis_settings/stop_freq: Number(10000000) vs Number(10000000.0)', 'Value mismatch at args/voltage_source_settings/primary_cascode_ac_stimulus: Number(1) vs Number(1.0)']\n```\n\n### Using Dot Notation\n\n```python\n# Dot notation works the same as slash notation\ndifferences = fastjsondiff.compare_json(\n    json1,\n    json2,\n    allow=[\"args.testbench_description\", \"args.voltage_source_settings\"]\n)\n```\n\n### Ignoring Specific Paths\n\n```python\n# Ignore the id field and all voltage source settings\ndifferences = fastjsondiff.compare_json(\n    json1,\n    json2,\n    ignore=[\"id\", \"args/voltage_source_settings\"]\n)\n```\n\n## Performance\n\nFastJSONDiff is designed for high performance:\n\n- **Rust Implementation**: Core logic is implemented in Rust for maximum speed\n- **Memory Efficient**: Minimal memory allocation during comparison\n- **Optimized Path Matching**: Efficient path matching algorithms for filtering\n\n## Development\n\n### Building from Source\n\n```bash\n# Clone the repository\ngit clone https://github.com/yourusername/fastjsondiff.git\ncd fastjsondiff\n\n# Install Rust (if not already installed)\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n\n# Install maturin\npip install maturin\n\n# Build and install in development mode\nmaturin develop\n```\n\n### Running Tests\n\n```bash\n# Run the test suite\npython test_fastjsondiff.py\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Changelog\n\n### 0.1.0\n\n- Initial release\n- Basic JSON comparison functionality\n- Path-based filtering with ignore and allow parameters\n- Support for both dot and slash notation in paths\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Fast JSON difference detection library with path-based filtering",
    "version": "0.1.0",
    "project_urls": {
        "Repository": "https://github.com/yourusername/fastjsondiff"
    },
    "split_keywords": [
        "json",
        " diff",
        " comparison",
        " rust",
        " fast",
        " performance"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ca5c91eb3881aa297c67ca4f43383f938a85ff01bd122e757bada30ae16fcd74",
                "md5": "a310ac692c5c783f6854ad254135e4ef",
                "sha256": "a6434406971ace27e5cb82cfa5754fcad203d1af476c2f0466b217f95122a6b1"
            },
            "downloads": -1,
            "filename": "fastjsondiff-0.1.0-cp312-cp312-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "a310ac692c5c783f6854ad254135e4ef",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 195614,
            "upload_time": "2025-08-21T05:13:16",
            "upload_time_iso_8601": "2025-08-21T05:13:16.632026Z",
            "url": "https://files.pythonhosted.org/packages/ca/5c/91eb3881aa297c67ca4f43383f938a85ff01bd122e757bada30ae16fcd74/fastjsondiff-0.1.0-cp312-cp312-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "765bcde0ccd511690cd8f4b90d0da54f2ab66f133167e21abf4f9c3fcfaea3c8",
                "md5": "0b299f9cde668cf12e786c9b5f33902a",
                "sha256": "ca4110afecc1f3ec5ae1027985413fea4a5bfb11c3d9632314cf7024b153009d"
            },
            "downloads": -1,
            "filename": "fastjsondiff-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0b299f9cde668cf12e786c9b5f33902a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11636,
            "upload_time": "2025-08-21T05:13:19",
            "upload_time_iso_8601": "2025-08-21T05:13:19.135673Z",
            "url": "https://files.pythonhosted.org/packages/76/5b/cde0ccd511690cd8f4b90d0da54f2ab66f133167e21abf4f9c3fcfaea3c8/fastjsondiff-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-21 05:13:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yourusername",
    "github_project": "fastjsondiff",
    "github_not_found": true,
    "lcname": "fastjsondiff"
}
        
Elapsed time: 1.10804s