Skip to main content

A JSON parser that only parses the parts you need.

Project description

SelectiveJSONParser

🎯 A memory-efficient JSON parser that extracts only the data you need using powerful pattern matching.

Python License: MIT PyPI version

🚀 Features

  • Memory Efficient: Parse only the JSON fields you need, reducing memory usage
  • Pattern Matching: Use intuitive patterns to specify exactly what data to extract
  • Nested Data Support: Extract data from deeply nested JSON structures
  • Array Processing: Selective parsing of array elements
  • Multiple Key Selection: Extract multiple fields using OR patterns
  • Zero Dependencies: Pure Python implementation with no external dependencies

📦 Installation

pip install SelectiveJSONParser

🔧 Quick Start

Basic Usage

from selectivejsonparser.parser import Parser

# Parse entire JSON (traditional parsing)
json_data = '{"name": "Alice", "age": 25, "city": "Wonderland"}'
result = Parser(json_data).parse()
# Returns: {"name": "Alice", "age": 25, "city": "Wonderland"}

# Parse only specific fields (selective parsing)
result = Parser(json_data, "name").parse()
# Returns: {"name": "Alice"}

Advanced Pattern Matching

Extract Nested Data

#### Multiple Field Selection

```python
json_data = '{"name": "Diana", "age": 22, "city": "Themyscira", "occupation": "Warrior"}'
result = Parser(json_data, "name|city").parse()
# Returns: {"name": "Diana", "city": "Themyscira"}

Array Processing

# Extract specific fields from array elements
json_data = '[{"name": "Eve", "age": 29}, {"name": "Frank", "age": 33}]'
result = Parser(json_data, "[name]").parse()
# Returns: [{"name": "Eve"}, {"name": "Frank"}]

# Extract from nested arrays
json_data = '{"users": [{"name": "Grace", "age": 27}, {"name": "Heidi", "age": 31}]}'
result = Parser(json_data, "users[name]").parse()
# Returns: {"users": [{"name": "Grace"}, {"name": "Heidi"}]}

Complex Nested Structures

json_data = '''
{
    "company": {
        "employees": [
            {"name": "Ivan", "role": "Developer", "salary": 75000},
            {"name": "Judy", "role": "Manager", "salary": 85000}
        ]
    }
}
'''
result = Parser(json_data, "company.employees[name]").parse()
# Returns: {"company": {"employees": [{"name": "Ivan"}, {"name": "Judy"}]}}

📝 Pattern Syntax

Pattern Description Example
key Extract single field "name"
key1.key2 Extract nested field "user.profile.email"
key1|key2 Extract multiple fields (OR) "name|age"
[pattern] Apply pattern to array elements "[name]"
key[pattern] Apply pattern to nested array "users[email]"
key1.key2[pattern] Complex nested array pattern "data.items[id|name]"

🎯 Use Cases

Large JSON Files

When working with large JSON files where you only need specific fields:

# Instead of loading entire 100MB JSON into memory
# Only extract the fields you need
large_json = load_large_json_file()
result = Parser(large_json, "metadata.timestamp|data.results[id|status]").parse()

API Response Processing

Extract only relevant data from API responses:

# GitHub API response - extract only repo names and stars
api_response = get_github_repos()
repos = Parser(api_response, "[name|stargazers_count]").parse()

Configuration Files

Parse complex configuration files selectively:

config_json = load_config()
db_config = Parser(config_json, "database.connection|database.pool").parse()

🧪 Testing

Run the test suite:

pytest tests/

📈 Performance

SelectiveJSONParser can significantly reduce memory usage when working with large JSON files:

  • Memory Usage: Up to 80% reduction when extracting small subsets
  • Parse Speed: Comparable to standard JSON parsing for small patterns
  • Scalability: Linear performance with JSON size and pattern complexity

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built with modern Python type hints for better developer experience
  • Inspired by the need for memory-efficient JSON processing in data-heavy applications

⭐ If you find this project useful, please consider giving it a star!

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

selective_json_parser-0.0.2.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

selective_json_parser-0.0.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file selective_json_parser-0.0.2.tar.gz.

File metadata

  • Download URL: selective_json_parser-0.0.2.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.13

File hashes

Hashes for selective_json_parser-0.0.2.tar.gz
Algorithm Hash digest
SHA256 536d9ff2de408b55d2ddb95b3b6c7f9ca5401691f4eba72ac0cf4d139a027dfd
MD5 748fa39acd725ed062998b9f62436722
BLAKE2b-256 c2f65118d985c8fc147f10bfa9ac21cb6dc215592d1ccce28f312eae5ae8cc82

See more details on using hashes here.

File details

Details for the file selective_json_parser-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for selective_json_parser-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 27ae32a8b39f68f7f6834c29b4269ff147c51b9f2ea77dbc6aef39c3785e2ed3
MD5 e32ad4d368d30735445ca6bd32d7ab74
BLAKE2b-256 cf239e0df8827eab76f27f2df0018b8ce0b1de026441c4255154e00b4c4aaf91

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