Process nested JSON data into tabular output using jmespath queries with Pydantic models
Project description
maketab
Make nested data tabular using jmespath queries with Pydantic models.
Multi-level explode
Query roots can nest. Give a root a parent (config) or a root= (annotation
API) and its query is evaluated within each element produced by that parent,
flattening nested lists to one output row per leaf element. Fields attached to an
ancestor level are broadcast onto every leaf row beneath them.
from maketab import SchemaConfig, maketab_from_config
config = SchemaConfig.model_validate({
"query_roots": [
{"name": "task", "query": "tasks", "explode": True},
{"name": "property", "parent": "task", "query": "properties", "explode": True},
],
"fields": [
{"name": "task_list_id", "type": "int", "query": "id"},
{"name": "task_name", "type": "str", "query": "name", "root": "task"},
{"name": "property_name", "type": "str", "query": "name", "root": "property"},
{"name": "property_value", "type": "str", "query": "value", "root": "property"},
],
})
data = [{"id": 100, "tasks": [
{"name": "do thing 1", "properties": [
{"name": "type", "value": "bug"},
{"name": "team", "value": "team a"},
]},
]}]
maketab_from_config(config, data).records # one row per property
Notes:
- Siblings: two roots sharing one
parentproduce the cartesian product within each parent element — they never combine elements across parents. - Depth: parent chains compose to arbitrary depth.
- Empty/missing lists: a parent whose child list is
[]or absent contributes zero rows (no row with null leaf fields).
The same nesting is available through the annotation API via Explode(root=...):
from typing import Annotated
from pydantic import BaseModel
from maketab import Query, Explode, maketab
task = Explode("tasks")
prop = Explode("properties", root=task) # nested within each task
class Row(BaseModel):
task_list_id: Annotated[int, Query("id")]
task_name: Annotated[str, Query("name", task)]
property_name: Annotated[str, Query("name", prop)]
maketab(data, Row)
Custom JMESPath functions
maketab adds a small catalog of custom JMESPath functions (currently
get and to_key_value_pairs) available in every query it evaluates.
See docs/jmespath-functions.md for the
full reference with signatures, types, and examples.
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
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 maketab-0.4.4.tar.gz.
File metadata
- Download URL: maketab-0.4.4.tar.gz
- Upload date:
- Size: 192.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2facffbf4ce0a9b5ba457bc24cbff045f101d0e0aefecc8b96a4c604a09bb3c
|
|
| MD5 |
f6a33691b0fb30c223ea9b3bf52f71f2
|
|
| BLAKE2b-256 |
f59ee18d86b2a10a28a6c1977019fabf9b480b045690d3ed81dd7cbe3a7627d9
|
File details
Details for the file maketab-0.4.4-py3-none-any.whl.
File metadata
- Download URL: maketab-0.4.4-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d17b1d51e7cee44c3172310cf3b9f96d1255ae80d3e1332cea1230ad9a4e767c
|
|
| MD5 |
1074e4c42a76c6964215ae9d64c6a6e2
|
|
| BLAKE2b-256 |
04b842c988a97124120cabae95a41c7d636cdb7d0977257869a41c692bf4f416
|