<?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 to print multiple JSON root elements? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415139#M73389</link>
    <description>&lt;P&gt;For this command above, i need to concat all string with "\", the line of json format are very long, above is only example code, is there any other way to get only for second json root elements ?&lt;/P&gt;

&lt;P&gt;| eval _raw="{&lt;BR /&gt;
     \"container_id\":\"0fce97fd907a806802eab9b27965dd35dd82bbe142d128294b34b8a8a2e42f23\",&lt;BR /&gt;
     \"container_name\":\"nginx\"&lt;BR /&gt;
         }&lt;BR /&gt;
     {&lt;BR /&gt;
     \"name\":\"eventBase1\",&lt;BR /&gt;
     \"hostname\":\"google.com\",&lt;BR /&gt;
     \"pid\":7&lt;BR /&gt;
     }"&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 00:09:42 GMT</pubDate>
    <dc:creator>amirrachman</dc:creator>
    <dc:date>2020-09-30T00:09:42Z</dc:date>
    <item>
      <title>How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415137#M73387</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I've data like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
"container_id":"0fce97fd907a806802eab9b27965dd35dd82bbe142d128294b34b8a8a2e42f23",
"container_name":"nginx",
"name":"eventBase0"
}
{
"name":"eventBase1",
"hostname":"google.com",
"pid":7
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This above format are contain 2 multiple json root elements which second value "eventBase1" not shown on interesting fields in splunk dashboard. My output format is i want to get the second value and print on a table such as below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;+++++++++++++++++++++++++++++++
+++ name | hostname | pid +++
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2019 06:55:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415137#M73387</guid>
      <dc:creator>amirrachman</dc:creator>
      <dc:date>2019-04-13T06:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415138#M73388</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{
\"container_id\":\"0fce97fd907a806802eab9b27965dd35dd82bbe142d128294b34b8a8a2e42f23\",
\"container_name\":\"nginx\"
    }
{
\"name\":\"eventBase1\",
\"hostname\":\"google.com\",
\"pid\":7
}"

| rename COMMENT AS "Everything above generates sample events; everything below is your solution"

| rex mode=sed "s/([\r\n\s]+\})([\r\n\s]+\{[\r\n\s]+)/\1::::{\n/g"
| rename _raw AS raw
| makemv delim="::::" raw
| mvexpand raw 
| rename raw AS _raw
| spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Apr 2019 17:49:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415138#M73388</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-04-13T17:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415139#M73389</link>
      <description>&lt;P&gt;For this command above, i need to concat all string with "\", the line of json format are very long, above is only example code, is there any other way to get only for second json root elements ?&lt;/P&gt;

&lt;P&gt;| eval _raw="{&lt;BR /&gt;
     \"container_id\":\"0fce97fd907a806802eab9b27965dd35dd82bbe142d128294b34b8a8a2e42f23\",&lt;BR /&gt;
     \"container_name\":\"nginx\"&lt;BR /&gt;
         }&lt;BR /&gt;
     {&lt;BR /&gt;
     \"name\":\"eventBase1\",&lt;BR /&gt;
     \"hostname\":\"google.com\",&lt;BR /&gt;
     \"pid\":7&lt;BR /&gt;
     }"&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:09:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415139#M73389</guid>
      <dc:creator>amirrachman</dc:creator>
      <dc:date>2020-09-30T00:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415140#M73390</link>
      <description>&lt;P&gt;Hi @amirrachman The problem here is you don't have your data as correct JSON format that's why Splunk couldn't extract those fields... If you want auto extraction you should have the following format in your case:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[{
     "container_id":"0fce97fd907a806802eab9b27965dd35dd82bbe142d128294b34b8a8a2e42f23",
     "container_name":"nginx"
     },
     {
     "name":"eventBase1",
     "hostname":"google.com",
     "pid":7
     }]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;i.e. JSON array&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 05:35:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415140#M73390</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2019-04-15T05:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415141#M73391</link>
      <description>&lt;P&gt;hi @harshpatel yes, in this case, the logs is not have correct json format, for reformating, yes I create an concat array, then how i got the second value which I want ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
 "name":"eventBase1",
 "hostname":"google.com",
 "pid":7
 }
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 07:12:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415141#M73391</guid>
      <dc:creator>amirrachman</dc:creator>
      <dc:date>2019-04-15T07:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415142#M73392</link>
      <description>&lt;P&gt;Hi @amirrachman ,&lt;/P&gt;

&lt;P&gt;You can either manually extract it at search time using &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/Rex"&gt;rex&lt;/A&gt; command like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "\"name\":\"(?&amp;lt;name&amp;gt;\w+)\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR &lt;BR /&gt;
You can reformat your data so that it is in proper JSON format so Splunk can auto extract fields for you. I would recommend the latter.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 07:26:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415142#M73392</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2019-04-15T07:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415143#M73393</link>
      <description>&lt;P&gt;Hi @harshpatel, the json that I've is like below.&lt;BR /&gt;
so I have both "name" field on the json files (I just revise my question on above). within those both "name", i want to take "name" on second value "eventBase1"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "container_id":"0fce97fd907a806802eab9b27965dd35dd82bbe142d128294b34b8a8a2e42f23",
    "container_name":"nginx",
    "name":"eventBase0"
    }
    {
    "name":"eventBase1",
    "hostname":"google.com",
    "pid":7
    }
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 09:05:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415143#M73393</guid>
      <dc:creator>amirrachman</dc:creator>
      <dc:date>2019-04-15T09:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415144#M73394</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "{\s*\"name\":\"(?&amp;lt;name&amp;gt;\w+)\""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 09:30:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415144#M73394</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2019-04-15T09:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415145#M73395</link>
      <description>&lt;P&gt;Thank @harshpatel it's working perfect as I want&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 15:00:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415145#M73395</guid>
      <dc:creator>amirrachman</dc:creator>
      <dc:date>2019-04-15T15:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to print multiple JSON root elements?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415146#M73396</link>
      <description>&lt;P&gt;You are TOTALLY missing the point.  Read the line that is singled out. It says &lt;CODE&gt;Everything above generates sample events; everything below is your solution&lt;/CODE&gt;.  You only need the stuff below that line, the portion that begins with &lt;CODE&gt;| rex ...&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 15:13:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-print-multiple-JSON-root-elements/m-p/415146#M73396</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-04-15T15:13:15Z</dc:date>
    </item>
  </channel>
</rss>

