I have JSON configuration of Grafana dashboard. I want to get spicific keys like
.rows[].title
.rows[].panels[].title
.rows[].panels[].description
.rows[].panels[].format
.rows[].panels[].targets[].expr
and transform it to new JSON with following structure:
[
{
"row_title": ".rows[].title",
"panels": [
{
"panel_title": ".rows[].panels[].title",
"panel_description": ".rows[].panels[].description",
"panel_format": ".rows[].panels[].format",
"panel_exprs": [
{
"expr": ".rows[].panels[].targets[].expr"
}
]
}
]
}
]
Tried to do it with map(), but cannot understand how make nested arrays.
CodePudding user response:
Is this what you are asking? Transforming the input array with all nested arrays and keeping only certain properties of each object? Any property not listed in the jq program will be ignored and dropped from the output.
map({
row_title,
panels: .panels | map({
panel_title,
panel_description,
panel_format,
panel_exprs: .panel_exprs | map({
expr
})
})
})