Splunk Search

json extract with non-existing fields

Albsoguero
New Member

Hi,

 

I have a json where not all the elements have all the fields. How can we extract and show this in a table?

 

For example:

 

"{

"node" :" node1",

"Command_output_interface" : [

        {

                  "TABLE_interface" : {

                            "ROW_interface" : [

                                     {

                                                 "interface" : "ethernet1/1",

                                                 "description" : "local",

                                     }

                                    {

                                                 "interface" : "ethernet1/2",

                                     }

                                     {

                                                 "interface" : "ethernet1/3",

                                                 "description" : "wan",

                                     }

                            ]

             }

}

]

}"

 

As you can see, ethernet1/2 is not having description.

 

When I try to table it using Spath and mvzip and mvextract, it is not working fine because it is shown in this way:

node               interface             description

node1           ethernet1/1       local

node1           ethernet1/2       wan

node1           ethernet1/3

 

And of course I want the following result, where there is no description for ethernet1/2:

     

node               interface             description

node1           ethernet1/1       local

node1           ethernet1/2       

node1           ethernet1/3       wan

 

Can you help me? Seems simple but I haven't been able to find the way.

 

Regards,

Labels (1)
0 Karma

to4kawa
Ultra Champion
index=_internal | head 1 | fields _raw 
| eval _raw="{\"node\":\" node1\",\"Command_output_interface\":[{\"TABLE_interface\":{\"ROW_interface\":[{\"interface\":\"ethernet1/1\",\"description\":\"local\"},{\"interface\":\"ethernet1/2\"},{\"interface\":\"ethernet1/3\",\"description\":\"wan\"}]}}]}"
| rename COMMNENT as "this is your sample. check this. from here, the logic"
| spath Command_output_interface{}.TABLE_interface.ROW_interface{} output=Coi
| spath node
| stats values(node) as node by Coi
| spath input=Coi
| fields - Coi
| table node interface description
0 Karma

Albsoguero
New Member

Yeah!! It worked totally for me. 🙂

 

Now I have to understand it. 😉

 

Regards!

 

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...