Splunk Search

How to parse JSON List

srajabi
Engager

Hey I have the following query:

 

```

| makeresults | eval prediction_str_body="[{'stringOutput':'Alpha','doubleOutput':0.52},{'stringOutput':'Beta','doubleOutput':0.48}]"

```

 

But no matter what I do, I can't seem to extract each element of the list and turn it into it's own event.

I'd ideally like a table afterwards of the sum of each value:

Alpha: 0.52
Beta: 0.48

For all rows.

Thanks!

Labels (1)
0 Karma

srajabi
Engager

Ah wonderful, thanks so much!

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Pro tip: It is great that you are using makeresults to post simulation.  But do not mangle JSON.

The command you are looking for is mvexpand.

 

| makeresults | eval prediction_str_body="[{\"stringOutput\":\"Alpha\",\"doubleOutput\":0.52},{\"stringOutput\":\"Beta\",\"doubleOutput\":0.48}]"
| spath input=prediction_str_body path={}
| mvexpand {}
| spath input={}

 

Your sample gives

doubleOutputstringOutput{}
0.48Beta{"stringOutput":"Beta","doubleOutput":0.48}

Hope this helps.

Tags (1)
Get Updates on the Splunk Community!

Get Schooled with Splunk Education: Explore Our Latest Courses

At Splunk Education, we’re dedicated to providing incredible learning experiences that cater to every skill ...

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL  The Splunk AI Assistant for SPL ...

Buttercup Games: Further Dashboarding Techniques (Part 5)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...