Splunk Search

How to extract values from a JSON like string?

kotig
Path Finder

I am having data like this in my Splunk and I wanted to extract the value of status which is Active.

How can I do it when this is not a valid JSON string?

 

 

mydata {
name {
value: "1111"
}
id {
value: "2020-07-02 15:49:00"
}
status {
value: "Active"
}
}
Any help is appreciated.

 

 

Labels (5)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@kotig You are not specifying field=message in the rex command, so it is looking at _raw which no longer exists after your table message statement

| makeresults
| eval message="mydata {
name {
value: \"1111\"
}
id {
value: \"2020-07-02 15:49:00\"
}
status {
value: \"Active\"
}
}"
| rex field=message "status \{\nvalue: \"(?<status>\w+)" | table status

 

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Assuming that's all one event, then rex should do the job.

... | rex "status \{\nvalue: \"(?<status>\w+)"

 

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

kotig
Path Finder

yea i tried the rex. But it did not work. What i did was search splunk and put them into a table and then tried the rex as mentioned above but i had no luck.

0 Karma

richgalloway
SplunkTrust
SplunkTrust
Please elaborate. What search did you use? What does the table look like? What rex did you try?
---
If this reply helps you, Karma would be appreciated.
0 Karma

kotig
Path Finder

index=mysearchIndex | table message | rex "status \{\nvalue: \"(?<status>\w+)" | table status

Here - message contains contains the string like below:

message

-----------

mydata {
name {
value: "1111"
}
id {
value: "2020-07-02 15:49:00"
}
status {
value: "Active"
}
}

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@kotig You are not specifying field=message in the rex command, so it is looking at _raw which no longer exists after your table message statement

| makeresults
| eval message="mydata {
name {
value: \"1111\"
}
id {
value: \"2020-07-02 15:49:00\"
}
status {
value: \"Active\"
}
}"
| rex field=message "status \{\nvalue: \"(?<status>\w+)" | table status

 

kotig
Path Finder

Thank you @richgalloway and @bowesmana . That worked.

0 Karma
Get Updates on the Splunk Community!

Enhance Your Splunk App Development: New Tools & Support

UCC FrameworkAdd-on Builder has been around for quite some time. It helps build Splunk apps faster, but it ...

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

This is the sixth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...