Splunk Search

Print string arrays in json in tabular format

ayushk23
Loves-to-Learn

I need to print a string array along with one field in my json object. 

The data:

 

{ "key1":"val1",  "key2":"value2",  "codes":["apple","mango","banana","orange"], "key3_conditional":"yes"}

 

 

My Search query:

 

<My search query>
| rex "\|(?<payload>[^\|]*)$"
| spath input=payload
| rex "\"codes\":\"(?<codes>[^\"]*)"
| eval is_unknown=if(isnotnull(key3_conditional), key3_conditional, "no")
| table codes, is_unknown

 

 

This only displays the 1st value in codes and I need all values of codes as comma separated.

 

 

Labels (2)
Tags (2)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| makeresults | eval _raw="{ \"key1\":\"val1\",  \"key2\":\"value2\",  \"codes\":[\"apple\",\"mango\",\"banana\",\"orange\"], \"key3_conditional\":\"yes\"}"
| spath path=codes{} output=codes
| spath path=key3_conditional
| table codes key3_conditional
0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...