<?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 Parsing a JSON string in search object in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422919#M169172</link>
    <description>&lt;P&gt;We changed how our data was getting into splunk instead of dealing with full JSON we're just importing the data straight from the database.  We have a dashboard that lets our consumer services team search by address, we're using &lt;CODE&gt;spath&lt;/CODE&gt; currently to parse the JSON.  We don't have to do that anymore with the new format but the &lt;CODE&gt;additional_information&lt;/CODE&gt; part of our object is still JSON, how can I parse this?&lt;/P&gt;

&lt;P&gt;This is that the data looks like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2017-01-04 16:41:34.439, id="60", created_at="2017-01-04 16:41:34.43926", updated_at="2017-01-04 16:41:34.43926", email="", encrypted_password="", token="", first_name="Brandon", last_name="Shega", additional_info=""{\"address_2\":\"\",\"city\":\"North Olmsted\",\"zip_code\":\"44070\",\"country\":\"us\",\"address_1\":\"23500 Al Moen Dr\",\"state\":\"Ohio\"}""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So &lt;CODE&gt;additional_info&lt;/CODE&gt; is really a string that contains a JSON object, is this possible to be parsed to be able to create a dropdown with the full address and search on that?&lt;/P&gt;</description>
    <pubDate>Tue, 29 May 2018 19:38:04 GMT</pubDate>
    <dc:creator>bshega</dc:creator>
    <dc:date>2018-05-29T19:38:04Z</dc:date>
    <item>
      <title>Parsing a JSON string in search object</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422919#M169172</link>
      <description>&lt;P&gt;We changed how our data was getting into splunk instead of dealing with full JSON we're just importing the data straight from the database.  We have a dashboard that lets our consumer services team search by address, we're using &lt;CODE&gt;spath&lt;/CODE&gt; currently to parse the JSON.  We don't have to do that anymore with the new format but the &lt;CODE&gt;additional_information&lt;/CODE&gt; part of our object is still JSON, how can I parse this?&lt;/P&gt;

&lt;P&gt;This is that the data looks like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2017-01-04 16:41:34.439, id="60", created_at="2017-01-04 16:41:34.43926", updated_at="2017-01-04 16:41:34.43926", email="", encrypted_password="", token="", first_name="Brandon", last_name="Shega", additional_info=""{\"address_2\":\"\",\"city\":\"North Olmsted\",\"zip_code\":\"44070\",\"country\":\"us\",\"address_1\":\"23500 Al Moen Dr\",\"state\":\"Ohio\"}""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So &lt;CODE&gt;additional_info&lt;/CODE&gt; is really a string that contains a JSON object, is this possible to be parsed to be able to create a dropdown with the full address and search on that?&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 19:38:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422919#M169172</guid>
      <dc:creator>bshega</dc:creator>
      <dc:date>2018-05-29T19:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a JSON string in search object</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422920#M169173</link>
      <description>&lt;P&gt;You should be able to use &lt;CODE&gt;| spath input=additional_info&lt;/CODE&gt; to parse that embedded json data and extract fields. If those escaped double quotes are causing issue with spath, you may have to correct it before using spath (either by eval-replace or rex-sed).&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 20:29:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422920#M169173</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-29T20:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a JSON string in search object</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422921#M169174</link>
      <description>&lt;P&gt;So, I've got something like this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=iot-productiondb source=Users | eval additional_info = replace(additional_info, "\\/", "") | eval additional_info = ltrim(additional_info, "\"") | eval additional_info = rtrim(additional_info, "\"") | spath input=additional_info | table additional_info
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm mostly just trying to make sure the JSON is parsing correctly with the &lt;CODE&gt;table&lt;/CODE&gt; command.  Does this look correct? I'm not sure how to actually access the information after the &lt;CODE&gt;spath&lt;/CODE&gt;.  I've tried something like &lt;CODE&gt;additional_info.country&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 14:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422921#M169174</guid>
      <dc:creator>bshega</dc:creator>
      <dc:date>2018-05-30T14:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a JSON string in search object</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422922#M169175</link>
      <description>&lt;P&gt;I actually noticed something else, no matter what I do, Splunk always puts the &lt;CODE&gt;additional_info&lt;/CODE&gt; as blank, I'm thinking it's because it's a string within a string (notice the double quotes at the beginning and end).  So I think Splunk is just taking the first set of quotes and saying that it's an empty string.  Is there a way to massage the data already in Splunk to remove the outer set of quotes?&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 20:09:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422922#M169175</guid>
      <dc:creator>bshega</dc:creator>
      <dc:date>2018-05-30T20:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a JSON string in search object</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422923#M169176</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/196131"&gt;@bshega&lt;/a&gt;, please try the following search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=iot-productiondb source=Users
|  eval _raw=replace(_raw,"\\\\\"","\"")
|  rex "additional_info=\"\"(?&amp;lt;additional_info&amp;gt;[^}]+})"
|  spath input=additional_info
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search to extract JSON data using &lt;CODE&gt;rex&lt;/CODE&gt; (first _raw data is cleaned up using &lt;CODE&gt;replace()&lt;/CODE&gt; function). Then &lt;CODE&gt;additional_info&lt;/CODE&gt; field is extracted from _raw event using rex command. Finally &lt;CODE&gt;spath&lt;/CODE&gt; is applied on the &lt;CODE&gt;additonal_info&lt;/CODE&gt; field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw=" 2017-01-04 16:41:34.439, id=\"60\", created_at=\"2017-01-04 16:41:34.43926\", updated_at=\"2017-01-04 16:41:34.43926\", email=\"\", encrypted_password=\"\", token=\"\", first_name=\"Brandon\", last_name=\"Shega\", additional_info=\"\"{\\\"address_2\\\":\\\"\\\",\\\"city\\\":\\\"North Olmsted\\\",\\\"zip_code\\\":\\\"44070\\\",\\\"country\\\":\\\"us\\\",\\\"address_1\\\":\\\"23500 Al Moen Dr\\\",\\\"state\\\":\\\"Ohio\\\"}\"\""
|  eval _raw=replace(_raw,"\\\\\"","\"")
|  rex "additional_info=\"\"(?&amp;lt;additional_info&amp;gt;[^}]+})"
|  spath input=additional_info
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Sample data generate using &lt;CODE&gt;| makeresults&lt;/CODE&gt; and &lt;CODE&gt;|eval raw=....&lt;/CODE&gt; has escaped characters in order to generate raw data as per the question.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:47:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parsing-a-JSON-string-in-search-object/m-p/422923#M169176</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T19:47:22Z</dc:date>
    </item>
  </channel>
</rss>

