Oh No! My JSON Keys and Values are Separated! How Can I Extract Them For My Searches?

By |Published On: March 11th, 2024|
Splunk parses pure JSON logs almost like magic. The format works really well for Splunk to automatically extract fields you would need in your searches. However, an issue arises when a JSON log separates the key and the value into two different key/value pairs where “key” and “value” become the fields. 

For example, a JSON log will often look like the below:

Splunk will be able to parse the fields timestamp, level, message, user, user{}.id, user{}.username, and ip_address with their corresponding values. So, you would be able to run the search index=donuts | table timestamp level message user{}.username ip_address and get the following results:


Easy, right? But what happens when the keys and values are not on the same line in the log? If the JSON log is formatted with a nested list of keys and values, then Splunk will extract it like so:

The fields will be moreInformation{}.key and moreInformation{}.value, not DonutId, DonutType, or DonutToppings. In a table this might be enough for your needs, but you may want to run searches that coordinate the keys to their values more explicitly. 

We get this automatically in Splunk, where the keys and values that we want are separated and not explicitly paired with each other.


And our goal is for these key/value pairs to be explicitly set for the searches we want to run: DonutId = 1234567

Our solution is to use a combination of the mvfind and mvindex eval functions: https://docs.splunk.com/Documentation/SCS/current/SearchReference/MultivalueEvalFunctions The mvfind function will help us identify which key we want to use for the field name, while the mvindex function will associate the value to the key we are using for a field. What happens is that new meaningful fields are created that you can now use in your search.

The search would look like this:

You would do this for each field that you want to use from the nested JSON. Find the key, then associate the corresponding value using the index location within the JSON. You can do this within the search or use the eval commands in a Calculated Field to reuse the fields easily in other searches.

Share with your network!
Get monthly updates from Hurricane Labs
* indicates required

About Hurricane Labs

Hurricane Labs is a dynamic Managed Services Provider that unlocks the potential of Splunk and security for diverse enterprises across the United States. With a dedicated, Splunk-focused team and an emphasis on humanity and collaboration, we provide the skills, resources, and results to help make our customers’ lives easier.

For more information, visit www.hurricanelabs.com and follow us on Twitter @hurricanelabs.

managed SOAR services