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!

AppDynamics Summer Webinars

This summer, our mighty AppDynamics team is cooking up some delicious content on YouTube Live to satiate your ...

SOCin’ it to you at Splunk University

Splunk University is expanding its instructor-led learning portfolio with dedicated Security tracks at .conf25 ...

Credit Card Data Protection & PCI Compliance with Splunk Edge Processor

Organizations handling credit card transactions know that PCI DSS compliance is both critical and complex. The ...