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.6.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.6-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for selective_json_parser-0.0.6.tar.gz
Algorithm Hash digest
SHA256 042749222b8397c1d498196781bf6a3f4d8d49cf1979a622390ba45a84f98329
MD5 7cbff62c5f80ed969b13195efffc9c64
BLAKE2b-256 f57d7c110a99482c2b615c0db91127ddeebe57e76bd9750aa2aaf0b60a6ed07b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for selective_json_parser-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 954d98c95ea781eddafc372708a2817bb7977890255267a1f28f379830ec0206
MD5 9b1b3f90a3be002a7aa1d8b19efe4929
BLAKE2b-256 7e2a130672411e7afd0b687a75581c215231d923f0de5970d07c64f346b70298

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