Splunk Search

How to regex over nested jsons with foreach and rex?

neuromantik
Engager

Hi everyone,

Currently I have a log record in the form of nested jsons, not arrays of jsons:

{"root_key": {"subkey_0": {nested json string}, ... , "subkey_N": {nested json string}}}

I want to extract some fields with rex from each subkey json string.
Is it possible somehow to accomplish this by foreach and rex?

Something like this pseudocode:

foreach subkey:
    (field_value_0, ... field_value_M) <--- rex(subkey json string)

The goal is to build the following list:

[
    [field_value_0, ... field_value_M],
    ...
    [field_value_0, ... field_value_M]
]

And to display it with table command.

0 Karma
1 Solution

to4kawa
Ultra Champion
| makeresults 
| eval _raw="{\"root_key\": {\"subkey_0\": {a},\"subkey_1\": {b} , \"subkey_N\": {c}}}" 
| rex ":(?<json>.+)}$"
| rex field=json max_match=1000 ": \{(?<field_value>.+?)\}"

limits: 1000 objects. if you want more, change max_match args.

View solution in original post

to4kawa
Ultra Champion
| makeresults 
| eval _raw="{\"root_key\": {\"subkey_0\": {a},\"subkey_1\": {b} , \"subkey_N\": {c}}}" 
| rex ":(?<json>.+)}$"
| rex field=json max_match=1000 ": \{(?<field_value>.+?)\}"

limits: 1000 objects. if you want more, change max_match args.

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...