<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Nested json array with missing fields into Splunk Table in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Nested-json-array-with-missing-fields-into-Splunk-Table/m-p/532093#M89479</link>
    <description>&lt;LI-CODE lang="markup"&gt;index=_internal | head 1 | fields _raw 
| eval _raw="{
\"index\":2,
\"rows\": [
{\"apple\": 29},
{\"carrot\": 12},
{\"carrot\": 54, \"apple\": 23},
{\"carrot\": 67, \"apple\":9}
]
}"
| spath index 
| spath rows{} output=rows
| stats count by rows index
| spath input=rows
| fields - count rows&lt;/LI-CODE&gt;</description>
    <pubDate>Sat, 05 Dec 2020 03:40:07 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-12-05T03:40:07Z</dc:date>
    <item>
      <title>Nested json array with missing fields into Splunk Table</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Nested-json-array-with-missing-fields-into-Splunk-Table/m-p/532086#M89476</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below JSON event with nested array in splunk -:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
   "index": 2,
   "rows": [
      {
         "apple": 29
      },
      {
         "carrot": 12
      },
      {
         "carrot": 54,
         "apple": 23
      },
      {
         "carrot": 67,
         "apple": 9
      }
   ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Important thing to consider is that few entries in json array can have one or more missing fields.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write splunk query which would create table like following:&lt;/P&gt;&lt;TABLE border="1" width="50%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;index&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;apple&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;carrot&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;29&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;54&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;23&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;67&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I could write a splunk query like following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{
\"index\":2,
\"rows\": [
{\"apple\": 29},
{\"carrot\": 12},
{\"carrot\": 54, \"apple\": 23},
{\"carrot\": 67, \"apple\":9}
]
}" 
| spath
| spath input=rows
| table index,rows{}.apple,rows{}.carrot&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it has two problems, 1- i need separate rows, 2 -&amp;nbsp; i need to maintain one-to-one mapping of individual columns&lt;/P&gt;</description>
      <pubDate>Sat, 05 Dec 2020 00:17:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Nested-json-array-with-missing-fields-into-Splunk-Table/m-p/532086#M89476</guid>
      <dc:creator>dheeru487</dc:creator>
      <dc:date>2020-12-05T00:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Nested json array with missing fields into Splunk Table</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Nested-json-array-with-missing-fields-into-Splunk-Table/m-p/532093#M89479</link>
      <description>&lt;LI-CODE lang="markup"&gt;index=_internal | head 1 | fields _raw 
| eval _raw="{
\"index\":2,
\"rows\": [
{\"apple\": 29},
{\"carrot\": 12},
{\"carrot\": 54, \"apple\": 23},
{\"carrot\": 67, \"apple\":9}
]
}"
| spath index 
| spath rows{} output=rows
| stats count by rows index
| spath input=rows
| fields - count rows&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 05 Dec 2020 03:40:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Nested-json-array-with-missing-fields-into-Splunk-Table/m-p/532093#M89479</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-12-05T03:40:07Z</dc:date>
    </item>
  </channel>
</rss>

