Splunk Search

How do I find events that have a specific value in an array of JSON strings?

cpomerantzuniso
New Member

I have a JSON object that includes a field that is an array of strings. So something like this:

{
  "tags": [
    "value1",
    "value2"
  ]
}

I want to find all of the events that contain a specific value like "value2". I tried using mvfind but that didn't seem to work, something like this:

index="logs" | where isnotnull(mvfind(tags, "value2"))

Can someone tell me how I can do this?

Thanks!

0 Karma

harsmarvania57
SplunkTrust
SplunkTrust

Hi @cpomerantzunison,

Please try below query (Here I am assuming that JSON data is already parsed and you have field called tags{})

index="logs" 
| rename tags{} AS tagvalue
| where (tagvalue LIKE "value2")

Below is run anywhere search which you can run on any splunk instance and check the output.

| makeresults
| eval field1="{
  \"tags\": [
    \"value1\",
    \"value2\"
  ]
}"
| append [ makeresults
| eval field1="{
  \"tags\": [
    \"value1\",
    \"value3\"
  ]
}" ]
| spath input=field1
| rename tags{} AS test_tag
| where (test_tag LIKE "value2")
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...