英文:
How to implement JSON based conditions
问题
我正在寻找一种基于JSON应用条件的技巧。请查看下面的示例,目标是筛选记录并仅选择那些具有"isDefault=true"的记录。是否有一种方法可以在不使用字符串搜索的情况下完成,因为字符串搜索似乎不太精确。
let T = datatable (id: int) [1, 2, 3];
T
| extend json = dynamic([{ "capabilities":"None", "isDefault":false, "isInitial":false, "name":"contoso.fr", "type":"Managed"},
{ "capabilities":"Mail", "isDefault":true, "isInitial":false, "name":"login.contoso.com", "type":"Managed"},
{ "capabilities":"Mail,Office", "isDefault":false, "isInitial":false, "name":"contoso.com", "type":"Managed"}])
| extend data = parse_json(json)
| where data.isDefault == true
| project id
希望这是您要的条件。
英文:
I'm looking for a technique to apply a condition based on JSON. Look at the sample below where the goal is to filter the records and only pick those with "isDefault=true". Is there a way to do it without using a string search, which appears sloppy.
let T = datatable (id: int) [1, 2, 3];
T
| extend json = dynamic([{ "capabilities":"None", "isDefault":false, "isInitial":false, "name":"contoso.fr", "type":"Managed"},{ "capabilities":"Mail", "isDefault":true, "isInitial":false, "name":"login.contoso.com", "type":"Managed"},{ "capabilities":"Mail,Office", "isDefault":false, "isInitial":false, "name":"contoso.com", "type":"Managed"}])
| extend data = parse_json(json)
| project id // isDefault == "true" //want this to be the condition
答案1
得分: 0
你可以使用mv-apply
运算符
例如:
print payload = dynamic(
[
{"capabilities": "None", "isDefault": false, "isInitial": false, "name": "contoso.fr", "type": "Managed"},
{"capabilities": "Mail", "isDefault": true, "isInitial": false, "name": "login.contoso.com", "type": "Managed"},
{"capabilities": "Mail,Office", "isDefault": false, "isInitial": false, "name": "contoso.com", "type": "Managed"}
])
| mv-apply with_itemindex = i payload on (
where payload.isDefault == true
)
payload | i |
---|---|
{"capabilities": "Mail","isDefault": true,"isInitial": false,"name": "login.contoso.com","type": "Managed"} | 1 |
英文:
you could use the mv-apply
operator
for example:
print payload = dynamic(
[
{"capabilities": "None", "isDefault": false, "isInitial": false, "name": "contoso.fr", "type": "Managed"},
{"capabilities": "Mail", "isDefault": true, "isInitial": false, "name": "login.contoso.com", "type": "Managed"},
{"capabilities": "Mail,Office", "isDefault": false, "isInitial": false, "name": "contoso.com", "type": "Managed"}
])
| mv-apply with_itemindex = i payload on (
where payload.isDefault == true
)
payload | i |
---|---|
{<br> "capabilities": "Mail",<br> "isDefault": true,<br> "isInitial": false,<br> "name": "login.contoso.com",<br> "type": "Managed"<br>} | 1 |
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论