<?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: How do you convert JSON into a table? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439340#M76604</link>
    <description>&lt;P&gt;@ShagVT &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | kv 
| fields statistics.metrics.*.* 
| rename statistics.metrics.* as * 
| eval FieldList="" 
| foreach * 
    [ eval FieldList=if("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;"!="FieldList",FieldList.","."&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;","") ] 
| eval FieldList=split(FieldList,",") 
| mvexpand FieldList 
| eval Queue=mvindex(split(FieldList,"."),0),Column=mvindex(split(FieldList,"."),1) 
| eval value="" 
| foreach * 
    [ eval value=if("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"==Queue.".".Column,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',value),{Column}=value ] | stats values(batched) as Batched, values(skipped) as Skipped values(dberror) as DBerror values(alreadyHandled) as Handled values(total) as Total by Queue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Sample Search:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"currentTime\":\"2019-01-31T13:02:23.622\",\"applicationStartTime\":\"2019-01-23T18:37:23.613\",\"version\":\"2018.04.0.10\",\"buildTime\":\"2018-11-07T20:29:13Z\",\"statistics\":{\"mostRecentMessageTimestamp\":\"1969-12-31T16:00\",\"metrics\":{\"total\":{\"batched\":155,\"skipped\":3,\"dberror\":7,\"alreadyHandled\":18,\"total\":183},\"queue1\":{\"batched\":10,\"skipped\":0,\"dberror\":1,\"alreadyHandled\":6,\"total\":17},\"queue2\":{\"batched\":20,\"skipped\":0,\"dberror\":2,\"alreadyHandled\":0,\"total\":22},\"queue3\":{\"batched\":30,\"skipped\":3,\"dberror\":0,\"alreadyHandled\":12,\"total\":45},\"queue4\":{\"batched\":40,\"skipped\":0,\"dberror\":0,\"alreadyHandled\":0,\"total\":40},\"queue5\":{\"batched\":50,\"skipped\":0,\"dberror\":4,\"alreadyHandled\":0,\"total\":54},\"unknown\":{\"batched\":5,\"skipped\":0,\"dberror\":0,\"alreadyHandled\":0,\"total\":5}}},\"database\":{\"status\":{\"activeConnections\":2,\"idleConnections\":48,\"threadsAwaitingConnection\":0,\"totalConnections\":50}}}" 
| kv 
| fields statistics.metrics.*.* 
| rename statistics.metrics.* as * 
| eval FieldList="" 
| foreach * 
    [ eval FieldList=if("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;"!="FieldList",FieldList.","."&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;","") ] 
| eval FieldList=split(FieldList,",") 
| mvexpand FieldList 
| eval Queue=mvindex(split(FieldList,"."),0),Column=mvindex(split(FieldList,"."),1) 
| eval value="" 
| foreach * 
    [ eval value=if("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"==Queue.".".Column,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',value),{Column}=value ] | stats values(batched) as Batched, values(skipped) as Skipped values(dberror) as DBerror values(alreadyHandled) as Handled values(total) as Total by Queue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2019 06:03:14 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2019-02-01T06:03:14Z</dc:date>
    <item>
      <title>How do you convert JSON into a table?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439339#M76603</link>
      <description>&lt;P&gt;I have an application that generates a JSON status record that looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"currentTime": "2019-01-31T13:02:23.622","applicationStartTime": "2019-01-23T18:37:23.613","version": "2018.04.0.10","buildTime": "2018-11-07T20:29:13Z",
"statistics": {"mostRecentMessageTimestamp": "1969-12-31T16:00",
    "metrics": {
        "total": {"batched": 155,"skipped": 3,"dberror": 7,"alreadyHandled": 18,"total": 183},
        "queue1": {"batched": 10,"skipped": 0,"dberror": 1,"alreadyHandled": 6,"total": 17},
        "queue2": {"batched": 20,"skipped": 0,"dberror": 2,"alreadyHandled": 0,"total": 22},
        "queue3": {"batched": 30,"skipped": 3,"dberror": 0,"alreadyHandled": 12,"total": 45},
        "queue4": {"batched": 40,"skipped": 0,"dberror": 0,"alreadyHandled": 0,"total": 40},
        "queue5": {"batched": 50,"skipped": 0,"dberror": 4,"alreadyHandled": 0,"total": 54},
        "unknown": {"batched": 5,"skipped": 0,"dberror": 0,"alreadyHandled": 0,"total": 5}}},
"database": {"status": {"activeConnections": 2,"idleConnections": 48,"threadsAwaitingConnection": 0,"totalConnections": 50}}}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is repeated by each instance of the application.  I've been asked to put together a dashboard that includes the &lt;STRONG&gt;metrics&lt;/STRONG&gt; data in nice human-readable tables.&lt;/P&gt;

&lt;P&gt;It's easy enough to isolate the most recent record:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex sourcetype=status host=abc111 | head 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's really not clear to me how to turn this into a table though.  I'd like something that looks approximately like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Queue      Batched   Skipped  DBError   Handled   Total
total      155       3        7         18        183
queue1     10        0        1         6         17
queue2     20        0        2         0         22
queue3     30        3        0         12        45
queue4     40        0        0         0         40
queue5     50        0        0         4         54
unknown    5         0        0         0         5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Notice that both the total row and the total column are already in the data and don't need to be calculated.&lt;/P&gt;

&lt;P&gt;Thank you so much for any help you can offer in this!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 21:27:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439339#M76603</guid>
      <dc:creator>ShagVT</dc:creator>
      <dc:date>2019-01-31T21:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do you convert JSON into a table?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439340#M76604</link>
      <description>&lt;P&gt;@ShagVT &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | kv 
| fields statistics.metrics.*.* 
| rename statistics.metrics.* as * 
| eval FieldList="" 
| foreach * 
    [ eval FieldList=if("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;"!="FieldList",FieldList.","."&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;","") ] 
| eval FieldList=split(FieldList,",") 
| mvexpand FieldList 
| eval Queue=mvindex(split(FieldList,"."),0),Column=mvindex(split(FieldList,"."),1) 
| eval value="" 
| foreach * 
    [ eval value=if("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"==Queue.".".Column,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',value),{Column}=value ] | stats values(batched) as Batched, values(skipped) as Skipped values(dberror) as DBerror values(alreadyHandled) as Handled values(total) as Total by Queue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Sample Search:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"currentTime\":\"2019-01-31T13:02:23.622\",\"applicationStartTime\":\"2019-01-23T18:37:23.613\",\"version\":\"2018.04.0.10\",\"buildTime\":\"2018-11-07T20:29:13Z\",\"statistics\":{\"mostRecentMessageTimestamp\":\"1969-12-31T16:00\",\"metrics\":{\"total\":{\"batched\":155,\"skipped\":3,\"dberror\":7,\"alreadyHandled\":18,\"total\":183},\"queue1\":{\"batched\":10,\"skipped\":0,\"dberror\":1,\"alreadyHandled\":6,\"total\":17},\"queue2\":{\"batched\":20,\"skipped\":0,\"dberror\":2,\"alreadyHandled\":0,\"total\":22},\"queue3\":{\"batched\":30,\"skipped\":3,\"dberror\":0,\"alreadyHandled\":12,\"total\":45},\"queue4\":{\"batched\":40,\"skipped\":0,\"dberror\":0,\"alreadyHandled\":0,\"total\":40},\"queue5\":{\"batched\":50,\"skipped\":0,\"dberror\":4,\"alreadyHandled\":0,\"total\":54},\"unknown\":{\"batched\":5,\"skipped\":0,\"dberror\":0,\"alreadyHandled\":0,\"total\":5}}},\"database\":{\"status\":{\"activeConnections\":2,\"idleConnections\":48,\"threadsAwaitingConnection\":0,\"totalConnections\":50}}}" 
| kv 
| fields statistics.metrics.*.* 
| rename statistics.metrics.* as * 
| eval FieldList="" 
| foreach * 
    [ eval FieldList=if("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;"!="FieldList",FieldList.","."&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;","") ] 
| eval FieldList=split(FieldList,",") 
| mvexpand FieldList 
| eval Queue=mvindex(split(FieldList,"."),0),Column=mvindex(split(FieldList,"."),1) 
| eval value="" 
| foreach * 
    [ eval value=if("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"==Queue.".".Column,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',value),{Column}=value ] | stats values(batched) as Batched, values(skipped) as Skipped values(dberror) as DBerror values(alreadyHandled) as Handled values(total) as Total by Queue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 06:03:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439340#M76604</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-02-01T06:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do you convert JSON into a table?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439341#M76605</link>
      <description>&lt;P&gt;Wow - this is really good. I've never come across the foreach command and things like &amp;lt;&amp;gt; and &amp;lt;&amp;gt; ... Now I need to spend some time trying to understand &lt;STRONG&gt;why&lt;/STRONG&gt; this works.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:40:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439341#M76605</guid>
      <dc:creator>ShagVT</dc:creator>
      <dc:date>2019-02-01T14:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do you convert JSON into a table?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439342#M76606</link>
      <description>&lt;P&gt;Wow - this is really good. I've never come across the foreach command and things like &amp;lt;&amp;gt; and &amp;lt;&amp;gt; ... Now I need to spend some time trying to understand &lt;STRONG&gt;why&lt;/STRONG&gt; this works.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:40:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/439342#M76606</guid>
      <dc:creator>ShagVT</dc:creator>
      <dc:date>2019-02-01T14:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do you convert JSON into a table?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/611723#M105913</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt; , I have similar requirement, i referred your solution. But i am not able to print the row in the any one value has the data 0. Is there anything to be added in the query to avoid such condition?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 09:58:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-convert-JSON-into-a-table/m-p/611723#M105913</guid>
      <dc:creator>anooshac</dc:creator>
      <dc:date>2022-09-02T09:58:32Z</dc:date>
    </item>
  </channel>
</rss>

