Skip to main content

PyPI version Python 3.8+ License: MIT

json-key-parser

You know the pattern. You get a response back from an API and you need three fields buried inside it. So you write response['data'][0]['user']['address']['city'], wrap it in a try/except because some records have the key and some don't, repeat for the next field, and suddenly you have twenty lines of boilerplate for what should be a one-liner. json-key-parser lets you declare the keys you want and hands them back — no traversal code, no try/excepts, no nested loops.

Quick Start

from json_parser import JsonParser

data = [{"first_name": "Alice", "last_name": "Smith", "birthday": "1990-04-15",
         "address": {"street": "12 Oak Ave", "city": "Portland", "zip": "97201"}},
        {"first_name": "Bob", "last_name": "Jones", "birthday": "1985-09-30",
         "address": {"street": "88 Pine St", "city": "Seattle", "zip": "98101"}}]

result = JsonParser(data, ["first_name", "last_name", "birthday"]).get_data()

Output:

[
    {
        "first_name": "Alice",
        "last_name": "Smith",
        "birthday": "1990-04-15"
    },
    {
        "first_name": "Bob",
        "last_name": "Jones",
        "birthday": "1985-09-30"
    }
]

Why json-key-parser?

  • Declare keys, skip the traversal — one call replaces nested loops across every record
  • Wildcard patterns — address* matches address, address1, address2, and any other variation
  • Duplicate values merged automatically — no deduplication code needed when a key appears at multiple levels
  • Works at any nesting depth — one level or ten, it finds the keys you asked for
  • Zero dependencies — pure Python stdlib, nothing to pin or audit

Wildcard Matching

Using the same data from above, address* matches any key that starts with address:

result = JsonParser(data, ["address*"]).get_data()

Output:

[
    {
        "address": {
            "street": "12 Oak Ave",
            "city": "Portland",
            "zip": "97201"
        }
    },
    {
        "address": {
            "street": "88 Pine St",
            "city": "Seattle",
            "zip": "98101"
        }
    }
]

This is especially useful when records are inconsistently structured — one record might have address, another address1 and address2. The pattern catches all of them without needing to know which variant each record uses.

Duplicate Key Merging

When the same key appears at more than one nesting level inside a single record, the values are automatically combined into a list. No deduplication code required.

contacts = [
    {
        "first_name": "Alice",
        "address1": {"street": "12 Oak Ave", "city": "Portland"},
        "address2": {"street": "99 River Rd", "city": "Portland"}
    },
    {
        "first_name": "Bob",
        "address": {"street": "88 Pine St", "city": "Seattle"}
    }
]

result = JsonParser(contacts, ["first_name", "street"]).get_data()

Output:

[
    {
        "first_name": "Alice",
        "street": [
            "12 Oak Ave",
            "99 River Rd"
        ]
    },
    {
        "first_name": "Bob",
        "street": "88 Pine St"
    }
]

Alice has two addresses, so street becomes a list of both values. Bob has one address, so street stays a plain string. The shape matches the data — you don't have to handle it yourself.

Installation

pip install json-key-parser

License

MIT. See the LICENSE file for details.

Metadata

Release files for json-key-parser 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json-key-parser 0.1.0
File Size Uploaded
json_key_parser-0.1.0.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json-key-parser 0.1.0
File Interpreter ABI Platform
json_key_parser-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / json_key_parser-0.1.0.tar.gz

Download URL json_key_parser-0.1.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
30214cd863322f4ad391d60bbdd8d4320b289266c82b6cbc10bfe3757ff93677
BLAKE2b-256 checksum
How to use checksums
3fb37a07d028271e67565f141986d808bdf8337592d7d981f639b732d9fee7c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.11.11 Darwin/25.2.0

Release files / json_key_parser-0.1.0-py3-none-any.whl

Download URL json_key_parser-0.1.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64fa0145311c14cd908268db4fb31af42558c9d139db43e81bb0d01529e08b5a
BLAKE2b-256 checksum
How to use checksums
39857877a44ff74a4f55ee0d86f142e3687a86cb66224f036ccad28e3524daf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.11.11 Darwin/25.2.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page