Getting Data In

Extracting specific JSON field where duplicate exists within array

greatapoc
New Member

I have a JSON feed that I'm trying to parse fields in and the event contains fields with identical names but are different based on the "measurementType" field. What search can I run to pull the specific data based on the measurementType? For example, if I do a search spath consumption{}.wNow it will return both 405.878 and -2980.273. I want to be able to pull each out separately. Thank you

alt text

0 Karma

Damien_Dallimor
Ultra Champion

You can create fields at search time with eval based on the value of a field by using curly braces.

So something like this might solve your problem.

... | eval consumption.{measurementType}.wNow = 'consumption.wNow' | table consumption*
0 Karma

kyaparla
Path Finder

There is no direct way, since its an array of json objects, and each field is multivalue field. You would probably want wNow value along with other values in the same array right?

Need to break each json object as individual json event and following search helps do that.

your search | rex mode=sed "s/^\{\"\w+\"\:\s*\[//g"
| rex mode=sed "s/\]\}$//g"
| rex mode=sed "s/\},\{/}\n{/g"
| multikv noheader=t

first line above removes this text from the event "{"consumption": [
second line removes ]}
third line inserts new line char between each json object in json array.
fourth one breaks each line in to separate event.

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...