Splunk Search

How to extract fields from JSON which is stored in another field?

pwunderlich
Engager

Hi

I am new here and I have an issue which is unsolvable for me. I hope some of you can help me.

The result of my Splunk search looks like the following:

2016-06-24 14:42:29,892 ERROR: eventId=3, incoming="{"eventId":5,"gameId":1,"networkId":1,"instanceId":1,"zoneId":1,"playerId":"123","date":14...}", transformed="null",....

Now I want to get access to the fields in the incoming field so that I can search the data later with R. For this reason, I need something like: extract pairdelim="," kvdelim=":", but I have absolutely no idea how I can do that.

Given that I am not a Splunk expert, it would be great if you can formulate your answer simple and understandable.

Thank you in advance for your help, and let me know if you need further information!

Tags (2)
0 Karma
1 Solution

somesoni2
Revered Legend

So, due to double quotes in the value of the incoming field, the default field extraction is not capturing the whole string. In this case, you'd have to setup a custom field extraction to do that. Give this a try

your base search | rex "incoming=\"(?<incoming>.+)\", transformed=" | spath incoming

View solution in original post

somesoni2
Revered Legend

So, due to double quotes in the value of the incoming field, the default field extraction is not capturing the whole string. In this case, you'd have to setup a custom field extraction to do that. Give this a try

your base search | rex "incoming=\"(?<incoming>.+)\", transformed=" | spath incoming

lshengfa
Engager

This is awesome. This is exactly what I need. I found out all my fields of json are extracted as "{" which is awkward.
Could you explain how your regex works if possible?
Thanks!!!

0 Karma

pwunderlich
Engager

Hi, thanks for you answer.

...| spath incoming does not work but ...| spath input=incoming works perfect!

0 Karma

somesoni2
Revered Legend

Does the field incoming in your event contains full json string that we see in the example? If yes, then use the spath option as suggested by @sundareshr below. If not, that needs to fixed (field extraction need to be set to capture full json string) before using spath.

0 Karma

pwunderlich
Engager

Does the field incoming in your event contains full json string that we see in the example?...

Yes it does, but the spath command does not work because the value of the incoming field is only { and not the whole JSON. I think the problem are the 2 quotation marks "{" but I am not sure.

0 Karma

sundareshr
Legend

Have you looked at the spath command http://docs.splunk.com/Documentation/Splunk/6.4.1/SearchReference/Spath

... | spath incoming | 
0 Karma

pwunderlich
Engager

Thank you for your answer, but spath does not working (see my comment above).

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...