Getting Data In

Parsing out a 32-char GUID from a nested JSON array

nickchow
New Member

I have a JSON object in Splunk that looks something like this:

{
  "myArr": [
    [
      "redbull",
      "2;2cf77a02b5f047bbb1ae4522d9e614a6;OpAJa;1YdsW;3Z;zs"
    ],
    ... <more arrays> ...
  ]
}

What I'd like to do is:

  1. Pull out the nested array that has a first value of "redbull"
  2. Pull out the 2nd string from the nested array.
  3. Pull out the 2nd semicolon delimited item from that string.

In this particular example, what I want is:

2cf77a02b5f047bbb1ae4522d9e614a6

Can anyone assist with this?

0 Karma

niketn
Legend

@nickchow, you can use spath to parse JSON data (https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath)
If you have enabled KV_MODE=json in props.conf for your data your JSON data should already be extracted without the spath command (https://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf#Field_extraction_configuration).

Following is a run anywhere search to mock up data as per question, you can add the command from | spath to your base search in your case:

|  makeresults
|  eval _raw="{
   \"myArr\":
     [
       \"redbull\",
       \"2;2cf77a02b5f047bbb1ae4522d9e614a6;OpAJa;1YdsW;3Z;zs\"
     ]
 }"
 |  spath
 |  rename "myArr{}" as "myArr"
 |  eval arr1=mvindex(myArr,0)
 |  eval arr2=mvindex(myArr,1)
 |  eval arr2=split(arr2,";")
 |  eval guid=mvindex(arr2,1)
 |  table _raw myArr arr1 arr2 guid
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...