Splunk Search

Querying log events based on field values nested inside a escaped raw JSON property

btsr
Explorer

Hi, I need some help with querying log events based on field values nested inside a escaped raw JSON object property. Below screenshot represents the complete JSON log event in "Show syntax highlighted" mode. I need to filter events based on properties in the parent JSON object and also combine field values from msg.object which is also a proper JSON object.

I tried rex, spath but couldn't filter the events the way I need. Any help is appreciated. Thanks.

I am looking for a query to filter events matching the highlighted fields in the Splunk event log screenshot. This is for a dashboard with dropdowns for app, clientName, requestType, and state fields. I should be able to filter the log events based on dropdown selection.

index=x05_dev app=mock-app msg.detail{}.value=value1 | search msg.object.headers.requestType="basic" | search msg.object.body.client.clientName="XyzClient" | search msg.object.body.order.details[*].address.state="MN"

Sample Splunk Log EventSample Splunk Log Event

Labels (2)
0 Karma

yeahnah
Motivator

Hi @btsr 

Can you provide the raw JSON as a code sample as this makes it easier to provide a working example that shows you what you need to do using SPL.

yeahnah_0-1681948314914.png

On a side note, you should look at cleaning this data up before it is ingested - basically object is showing the HTML code for a double quote - " = &#34.

0 Karma

btsr
Explorer

I think we need to get the msg.object and replace all HTML codes to double quotes on the fly to make a valid JSON before querying further. 

 

{
  "app": "mock-app",
  "sessionId": "71cde99f-faa9-47df-99d4-97b81b39275b",
  "msg": {
    "event": "response",
    "status": "success",
    "details": [
      {
        "key": "key1",
        "value": "value1"
      }
    ],
    "method": "post",
    "object":{
      \u0026#34;headers\u0026#34;: {
        \u0026#34;content-length\u0026#34;: \u0026#34;225\u0026#34;,
        \u0026#34;requestType\u0026#34;: \u0026#34;basic\u0026#34;
      },
      \u0026#34;body\u0026#34;: {
        \\\u0026#34;client\\\u0026#34;: {
            \\\u0026#34;clientName\\\u0026#34;: \\\u0026#34;XyzClient\\\u0026#34;
        },
        \\\u0026#34;order\\\u0026#34;: {
            \\\u0026#34;number\\\u0026#34;: \\\u0026#34;551270009\\\u0026#34;,
            \\\u0026#34;details\\\u0026#34;: [
            {
                \\\u0026#34;item\\\u0026#34;: \\\u0026#34;product\\\u0026#34;,
                \\\u0026#34;address\\\u0026#34;: {
                  \\\u0026#34;street\\\u0026#34;: \\\u0026#34;Main St\\\u0026#34;,
                  \\\u0026#34;zip\\\u0026#34;: \\\u0026#34;12345\\\u0026#34;,
                  \\\u0026#34;state\\\u0026#34;: \\\u0026#34;MN\u0026#34;,
                \\\u0026#34;city\\\u0026#34;: \\\u0026#34;XyzCity\\\u0026#34;
            }
          }
        ]
      }
    }  
    }
  }
}

 

0 Karma

btsr
Explorer

Thanks @yeahnah, the msg.object field is ingested with HTML code like shown in the screenshot by the Splunk team to allow different teams to use it for different free form JSON format. If I click on "Show as Raw Text" in Splunk, it is replacing all ampersand symbol with \u0026

0 Karma

yeahnah
Motivator

Hi @btsr 

Try adding this sed character replacement using the rex command, which should normalise the escaped code in the msg.object back to double quotes expected for JSON formats, then spath will pull the kv fields out of the JSON event again

 

... your search ...
| rex mode=sed "s/(\\\)*u0026#34;/\"/g"
| spath msg.object
| ... more SPL, as needed ...

 

 Hope it helps

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...