Getting Data In

How to zip multiple cardinalities of nested json arrays?

cblanton
Communicator

We are trying to zip and expand several levels of nested json data. Here is an example of our json data. Below is an example of the desired output.

   {
     "level0": {
         "globalname": "TOP_A",
         "globalver": "1",
         "level1": { 
           "level2": [ 
               {
                "lvl2name": "LVL2A", 
                "warnings": { 
                    "totalcount": "26",
                    "rulebreakdown": [
                    { 
                      "rulecount": "2",
                      "rulename": "ruleA"
                    },
                    { 
                     "rulecount": "24",
                     "rulename": "ruleB"
                    }
                 ]
               }
              },

              {
                "lvl2name": "LVL2B", 
                "warnings": { 
                    "totalcount": 81,
                    "rulebreakdown": [
                    { 
                      "rulecount": "11",
                      "rulename": "ruleG"
                    },
                    { 
                     "rulecount": "67",
                     "rulename": "ruleR"
                    },
                    { 
                     "rulecount": "3",
                     "rulename": "ruleZ"
                    }
                 ]
               }
              }
           ]
          }
        }
    }

    {
      "level0": {
          "globalname": "TOP_D",
          "globalver": "1.5",
          "level1": { 
            "level2": [ 
                {
                 "lvl2name": "LVL6A", 
                 "warnings": { 
                     "totalcount": "2",
                     "rulebreakdown": [
                     { 
                       "rulecount": "2",
                       "rulename": "ruleAB"
                     }
                  ]
                }
               }

               {
                 "lvl2name": "LVL6D", 
                 "warnings": { 
                     "totalcount": "23",
                     "rulebreakdown": [
                     { 
                       "rulecount": "5",
                       "rulename": "ruleGG"
                     }
                     { 
                      "rulecount": "14",
                      "rulename": "ruleRG"
                    }
                    { 
                     "rulecount": "4",
                     "rulename": "ruleGZ"
                   }
                  ]
                }
               }
            ]
           }
         }
     }

This would be the desired output of these two events:

alt text

Labels (1)
0 Karma

to4kawa
Ultra Champion
| makeresults 
| eval _raw="[{\"level0\":{\"globalname\":\"TOP_A\",\"globalver\":\"1\",\"level1\":{\"level2\":[{\"lvl2name\":\"LVL2A\",\"warnings\":{\"totalcount\":\"26\",\"rulebreakdown\":[{\"rulecount\":\"2\",\"rulename\":\"ruleA\"},{\"rulecount\":\"24\",\"rulename\":\"ruleB\"}]}},{\"lvl2name\":\"LVL2B\",\"warnings\":{\"totalcount\":81,\"rulebreakdown\":[{\"rulecount\":\"11\",\"rulename\":\"ruleG\"},{\"rulecount\":\"67\",\"rulename\":\"ruleR\"},{\"rulecount\":\"3\",\"rulename\":\"ruleZ\"}]}}]}}},{\"level0\":{\"globalname\":\"TOP_D\",\"globalver\":\"1.5\",\"level1\":{\"level2\":[{\"lvl2name\":\"LVL6A\",\"warnings\":{\"totalcount\":\"2\",\"rulebreakdown\":[{\"rulecount\":\"2\",\"rulename\":\"ruleAB\"}]}},{\"lvl2name\":\"LVL6D\",\"warnings\":{\"totalcount\":\"23\",\"rulebreakdown\":[{\"rulecount\":\"5\",\"rulename\":\"ruleGG\"},{\"rulecount\":\"14\",\"rulename\":\"ruleRG\"},{\"rulecount\":\"4\",\"rulename\":\"ruleGZ\"}]}}]}}}]"
| spath {} output=root
| stats count by root
| spath input=root level0.level1.level2{} output=level2
| stats values(root) as root by level2
| spath input=level2 warnings.rulebreakdown{} output=rulebreakdown
| mvexpand rulebreakdown
| spath input=level2 warnings.totalcount output=totalcount
| spath input=rulebreakdown
| spath input=root level0 output=level0
| spath input=level0
| fields - level* root rulebreakdown

That's a lot of work.

0 Karma
Get Updates on the Splunk Community!

Exporting Splunk Apps

Join us on Monday, October 21 at 11 am PT | 2 pm ET!With the app export functionality, app developers and ...

Cisco Use Cases, ITSI Best Practices, and More New Articles from Splunk Lantern

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

Build Your First SPL2 App!

Watch the recording now!.Do you want to SPL™, too? SPL2, Splunk's next-generation data search and preparation ...