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)
    )

1 Answer 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
)
Sign up to request clarification or add additional context in comments.

2 Comments

How about when there are multiple rows? Each row has that json array.
generally speaking - it'd be very similar. you may want to consider providing a sample input (as done above), but also - your desired output - that may help in giving you an answer you'd be happy with

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.