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

🚀 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.1.tar.gz (8.2 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.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: selective_json_parser-0.0.1.tar.gz
  • Upload date:
  • Size: 8.2 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.1.tar.gz
Algorithm Hash digest
SHA256 58fd2a7a84b1aa8767bf1c27986716d6b4c52796337208f42f6e61c928eff3e5
MD5 8a0cafcd61d765eb6b18e25a60afdb16
BLAKE2b-256 e3cba568486091b4b4f29e8b89df069031ab73c3d5ac5d5b9d3b06c7aad23453

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for selective_json_parser-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3645bf9f2c07ab6c5fe7e998b13c892d3a3a18509f838b4578c527ea5eaa9878
MD5 29a663ce05ff9a3225a1b4771ea4fe1c
BLAKE2b-256 fc1d895f59afb8d885cf0ff38d791492794ef57e5399422512ed6e2b16a8cb0f

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