<?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 parse a JSON array that follows my search string? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258646#M77469</link>
    <description>&lt;P&gt;Perfect. This gives the entire content within {}. It is a single string. I should be able to work with it.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2016 19:38:09 GMT</pubDate>
    <dc:creator>splunk_skr</dc:creator>
    <dc:date>2016-11-30T19:38:09Z</dc:date>
    <item>
      <title>How to parse a JSON array that follows my search string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258644#M77467</link>
      <description>&lt;P&gt;My log file has multiple JSONs being printed in one line.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{JSON string 1}
My Search String : {"key1":"value1","key2":"value2"}
{JSON string 3}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to read the JSON that follows my search string, then get data for the key value pairs. So basically the JSON I need is between the &lt;CODE&gt;{}&lt;/CODE&gt; following my search string. I can play with the JSON after I get it. Any idea how I can extract just that json data?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 15:58:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258644#M77467</guid>
      <dc:creator>splunk_skr</dc:creator>
      <dc:date>2016-11-30T15:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON array that follows my search string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258645#M77468</link>
      <description>&lt;P&gt;Please try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your query to return the event
| rex field=_raw "(?s).*(My Search String)\s*\:\s*\{(?&amp;lt;myJson&amp;gt;[^\}]+)\}"
| table myJson
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Replace your search string with &lt;CODE&gt;(My Search String)&lt;/CODE&gt; above taking care of escaping any special characters, like &lt;CODE&gt;" . or * etc.&lt;/CODE&gt; in between that string if it is different.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/aGBxOf/2"&gt;See here for the output of regex&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 17:13:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258645#M77468</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-11-30T17:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON array that follows my search string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258646#M77469</link>
      <description>&lt;P&gt;Perfect. This gives the entire content within {}. It is a single string. I should be able to work with it.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 19:38:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258646#M77469</guid>
      <dc:creator>splunk_skr</dc:creator>
      <dc:date>2016-11-30T19:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON array that follows my search string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258647#M77470</link>
      <description>&lt;P&gt;@gokadroid I used the rex you suggested and that returned the data between {}. table option put it under one column. Here is how it looks&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"key1":"value1","key2":"value2"
"key1":"value1","key2":"value2"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to create a table with key1, key2 as headers and value1, value2 as the actual values inside it. Here is what i did &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    query to return event | rex field=_raw "(?s).*(My Search String)\s*\:\s*\{(?&amp;lt;myJson&amp;gt;[^\}]+)\}" | mvexpand myJson
     | eval str=split(myJson,",") 
     | eval col1=mvindex(str,0) 
     | eval col2=mvindex(str,1)
| table  col1, col2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is working but i get both key &amp;amp; value in column data. Is there a better way to get a cleaner table.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 22:17:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258647#M77470</guid>
      <dc:creator>splunk_skr</dc:creator>
      <dc:date>2016-11-30T22:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON array that follows my search string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258648#M77471</link>
      <description>&lt;P&gt;Indeed there always is a better way:&lt;/P&gt;

&lt;P&gt;How about we try to make &lt;CODE&gt;key&lt;/CODE&gt; and &lt;CODE&gt;value&lt;/CODE&gt; out of all the kv which exist in this string by doing something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;query to return event 
| rex field=_raw "(?s).*(My Search String)\s*\:\s*\{(?&amp;lt;myJson&amp;gt;[^\}]+)\}" 
| rex field=myJson max_match=0 "\"(?&amp;lt;key&amp;gt;[^\"]+)\":\"(?&amp;lt;value&amp;gt;[^\"]+)\""
| eval myKV=mvzip( key, value, "~")
| mvexpand myKV
| rex field=myKV "(?&amp;lt;myKey&amp;gt;[^~]+)~(?&amp;lt;myValue&amp;gt;.*)"
| table myKey, myValue
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Dec 2016 01:53:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258648#M77471</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-12-01T01:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a JSON array that follows my search string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258649#M77472</link>
      <description>&lt;P&gt;This works but not completely  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; . What i am looking for is a transpose. This query prints multiple rows for one result - key/values put in multiple rows. I need all values in one row.  Table Header Row for all Keys and values in multiple rows/columns under each header.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 19:55:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-JSON-array-that-follows-my-search-string/m-p/258649#M77472</guid>
      <dc:creator>splunk_skr</dc:creator>
      <dc:date>2016-12-09T19:55:15Z</dc:date>
    </item>
  </channel>
</rss>

