Splunk Search

extract json from string

ashodha
Engager

hi, I have a string int the following format:

msg: Logging interaction event { eventId: '12dea8c0-dfb2-4988-9e97-314dd6243918', eventAction: 'Failed', eventType: '123event', eventSubtype: '1234eventsub', domainName: 'common', appName: 'authentication', containerName: 'root', containerVersion: '0.0.973' }

i am unable to extract eventType and eventSubtype   because of text "Logging interaction event" how cna i get rid of this text and extract these fields

 

 

Labels (3)
0 Karma
1 Solution

ericjorgensenjr
Path Finder

This should work:

 

| rex field=msg "(?<json>{[^\}]+})" | eval json=replace(replace(json,"(\w+):","\"\1\":"),"'([^']+)'","\"\1\"") | spath input=json

View solution in original post

Tags (1)

ericjorgensenjr
Path Finder

This should work:

 

| rex field=msg "(?<json>{[^\}]+})" | eval json=replace(replace(json,"(\w+):","\"\1\":"),"'([^']+)'","\"\1\"") | spath input=json
Tags (1)

richgalloway
SplunkTrust
SplunkTrust

I like the way you fixed the quoting in the json.

---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

You can use the rex command to strip out the undesired text, but I doubt it will help.  This example query still fails.

| makeresults 
| eval _raw="msg: Logging interaction event { eventId: '12dea8c0-dfb2-4988-9e97-314dd6243918', eventAction: 'Failed', eventType: '123event', eventSubtype: '1234eventsub', domainName: 'common', appName: 'authentication', containerName: 'root', containerVersion: '0.0.973' }" 
| rex "(?<field2>\{[\s\S]+})" 
| spath input=field2

The search log reports:

WARN  SPathCommand - Some events are not in XML or JSON format.  Fields will not be extracted from these events.
---
If this reply helps you, Karma would be appreciated.
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 ...