Extract specific keys from deeply nested JSON structures with wildcards and zero dependencies
Project description
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*matchesaddress,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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file json_key_parser-0.1.0.tar.gz.
File metadata
- Download URL: json_key_parser-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.11 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30214cd863322f4ad391d60bbdd8d4320b289266c82b6cbc10bfe3757ff93677
|
|
| MD5 |
b553057fe8c11903de547bd47804eda8
|
|
| BLAKE2b-256 |
3fb37a07d028271e67565f141986d808bdf8337592d7d981f639b732d9fee7c6
|
File details
Details for the file json_key_parser-0.1.0-py3-none-any.whl.
File metadata
- Download URL: json_key_parser-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.11 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64fa0145311c14cd908268db4fb31af42558c9d139db43e81bb0d01529e08b5a
|
|
| MD5 |
ab03e723749e5a76a2b8bad0d05d66f8
|
|
| BLAKE2b-256 |
39857877a44ff74a4f55ee0d86f142e3687a86cb66224f036ccad28e3524daf0
|