Splunk Dev

How do I extract a field from the _raw data

danielsan
New Member

Hi guys,

Tried my best googling an answer but have not been able to find something that fits my requirement.

I have the following raw_data:

... \"number_of_goods\":10,\"number_of_locations\":5, ...

How do I create a field called number_of_goods and number_of_locations where the value is 10 and 5?

Many thanks in advance!

Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try the rex command. The backslashes are needed to escape the backslashes and quotes in your data.

<your search> | rex "number_of_goods\\\\\":(?<numberOfGoods>\d+),\\\\\"number_of_locations\\\\\":(?<numberOfLocations>\d+)" | ...
---
If this reply helps you, Karma would be appreciated.

danielsan
New Member

It works, you really saved my day. I have one follow-up question though. I'm trying to extract a similar field but it has a decimal value, e.g. 0.25 and with the rex example I got from you, I only get the first digit before the decimal and I can't figure out how to get the full value.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The regex for a floating point number is \d+\.\d+.

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

richgalloway
SplunkTrust
SplunkTrust

If your problem is resolved, please accept the answer to help future readers.

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

FrankVl
Ultra Champion

I guess you could also avoid having to mess with those backslashes and escaped quotes, by doing:

| rex "number_of_goods[^:]+:(?<numberOfGoods>\d+),[^\w]+number_of_locations[^:]+:(?<numberOfLocations>\d+)"

https://regex101.com/r/RgxoTh/1

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!

Data Management Digest – September 2026

    Welcome to the September 2026 edition of Data Management Digest! September brought a fresh wave of ...

Federated Search for CloudWatch Unified Data Store Is Generally Available

As organizations modernize their cloud environments, AWS workloads generate more security, operational, and ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...