如何在 Azure 数据资源管理器中将自定义 key/value 对字符串解析为 JSON 对象?
How to parse a custom key/value pair string into a JSON object in Azure Data Explorer?
我需要将一串属性解析为 JSON 对象。这是输入格式:
"var1=[val1] & var2=[val2] & var3=[val3] & var4=[val4]"
所需的输出:
{
"var1": "val1",
"var2": "val2",
"var3": "val3",
"var4": "val4"
}
我有答案,看下面...
Thanks Ziad Hammoud for providing this cool workaround!
print str = "var1=[val1] & var2=[val2] & var3=[val3] & var4=[val4]"
| extend str = replace("\] & ", "&", replace("=\[", "=", str))
| project Properties = parse_urlquery(str)['Query Parameters']
| where Properties.var2== "val2"
另一种方法是使用 extract_all()
,然后 'converting' 使用 pack()
和 make_bag()
将数组 属性 坏:
print str = "var1=[val1] & var2=[val2] & var3=[val3] & var4=[val4]"
| project Properties = extract_all(@"(?P<key>\w+)?=\[(?P<value>.*?)\]", dynamic(["key","value"]), str)
| mv-apply Properties on (
summarize make_bag(pack(tostring(Properties[0]), Properties[1]))
)
我需要将一串属性解析为 JSON 对象。这是输入格式:
"var1=[val1] & var2=[val2] & var3=[val3] & var4=[val4]"
所需的输出:
{
"var1": "val1",
"var2": "val2",
"var3": "val3",
"var4": "val4"
}
我有答案,看下面...
Thanks Ziad Hammoud for providing this cool workaround!
print str = "var1=[val1] & var2=[val2] & var3=[val3] & var4=[val4]"
| extend str = replace("\] & ", "&", replace("=\[", "=", str))
| project Properties = parse_urlquery(str)['Query Parameters']
| where Properties.var2== "val2"
另一种方法是使用 extract_all()
,然后 'converting' 使用 pack()
和 make_bag()
将数组 属性 坏:
print str = "var1=[val1] & var2=[val2] & var3=[val3] & var4=[val4]"
| project Properties = extract_all(@"(?P<key>\w+)?=\[(?P<value>.*?)\]", dynamic(["key","value"]), str)
| mv-apply Properties on (
summarize make_bag(pack(tostring(Properties[0]), Properties[1]))
)