Dashboards & Visualizations

how to read nested dictionary where the keys are dotted-strings

GaryZ
Path Finder

how to read nested dictionary where the keys are dotted-strings

I have the following posted dictionary

process_dict = {

     task.com.company.job1 {

           duration = value1

     }

     task.com.company.job2

    {

           duration = value2

     }

     task3.com.company.job1 =

    {

           duration = value3

     }

}

 

I did the following 

| spath path=result.process_dict output=process_data
| eval d_json = json(process_data), d_keys = json_keys(d_json), d_mv = json_array_to_mv(d_keys)

...
| eval duration_type = ".duration"
...
| eval duration = json_extract(process_data, d_mv.'duration_type')

I am not able to capture the value from "duration" key.

HOWEVER, if the key was just a single word (without '.'), this would work.

ie.      task_com    instead of      task.com.company.job2

 

TIA

Labels (5)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

json_extract is documented as not handling periods in the names and suggests using json_extract_exact, but it does not appear to work with an array of keys 

| makeresults
| fields - _time
| eval splunk_path="{\"system.splunk.path\":\"/opt/splunk/\",\"system.splunk.path2\":\"/opt/splunk/\"}"
| eval paths=mvappend("system.splunk.path","system.splunk.path2")
| eval extracted_path=json_extract_exact(splunk_path, "system.splunk.path")
| eval extracted_path2=json_extract_exact(splunk_path, "system.splunk.path2")
| eval extracted_paths=json_extract_exact(splunk_path, paths)
0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...