1

I have an json array logged as

[
  {
    "Key": "key0",
    "Value": 0
  },
  {
    "Key": "key1",
    "Value": 2
  }
]

How do I get Value for Key with value key0, so 0.

I have been using this kluge.

...
| extend jsonarray = parse_json(...)
| extend value = toint(case(
    jsonarray[0].Key == 'key0', jsonarray[0].Value,
    jsonarray[1].Key == 'key0', jsonarray[1].Value,
    "<out-of-range>"))

Update:

Using mv-apply:

| extend jsonarray = parse_json(...)
| mv-apply jsonarray on (
    where jsonarray.Key == 'key0'
    | project value = toint(jsonarray.Value)
    )
4

1 回答 1

3

you could use mv-expand or mv-apply:

print d = dynamic([
  {
    "Key": "key0",
    "Value": 0
  },
  {
    "Key": "key1",
    "Value": 2
  }
])
| mv-apply d on (
    where d.Key == "key0"
    | project d.Value
)
于 2019-12-17T15:37:57.310 回答