glom
glom copied to clipboard
how can I find item in an deeply nested data struct?
how could I find branch item by name (may be name='branch-a-a-a' , or maybe name='branch-b' ) from a deeply (may be depth > 10) nested json? Can anyone help me ? thanks.
{
"root": [
{
"type": "branch",
"name": "branch-a",
"children": [
{
"type": "branch",
"name": "branch-a-a",
"children": [
{
"type": "branch",
"name": "branch-a-a-a",
"children": [
{
"type": "leaf",
"name": "leaf-a"
},
{
"type": "leaf",
"name": "leaf-aa"
}
]
}
]
}
]
},
{
"type": "branch",
"name": "branch-b",
"children": [
{
"type": "leaf",
"name": "leaf-ba"
},
{
"type": "leaf",
"name": "leaf-bb"
}
]
}
]
}
Hey @rhinoceros! glom is primarily for when you know the structure of your input and output data. When you need something more dynamic, I've written a separate tool, called remap:
I'd use the visit
function to check for a value and then capture the path
and key
to get your answer.