我有一个属性包(json对象),不幸的是,它具有通过动态命名的属性而不是实际数组构成的对象数组。包中还有其他属性。例如:
{
"something": "whatever",
"another": "doesn't matter",
"thing1": "value1",
"thing2": "value2",
"thing3": "value3"
}
最终我想每个thing
排一行:
value1
value2
value3
我知道我可以使用mv-expand
将数组或属性包转换为多行,但我不确定该如何做
如果重要的话,每个财产袋的物品数量差异很大。通常只有一个,但有时是10-20,很少会是100或更多。
您可以尝试使用mv-apply
:
datatable(d:dynamic)
[
dynamic({"something":"whatever","another":"doesn'tmatter","thing1":"value1","thing2":"value2","thing3":"value3"}),
dynamic({"somethingelse":"whatever2","another":"doesn'tmatter2","thing1":"value12","thing2":"value22","thing3":"value32"}),
]
| mv-apply d on (
extend key = tostring(bag_keys(d)[0])
| where key startswith "thing"
| project value = d[key]
)
返回:
| value |
|---------|
| value1 |
| value2 |
| value3 |
| value12 |
| value22 |
| value32 |