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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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