<?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 string JSON along with actual JSON? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594719#M206996</link>
    <description>&lt;P&gt;Then you'd have to manipulate the event manually. Which could probably be possible in some specific cases but it'd be hard to do in general case. Firstly you'd have to remove the original contents of the field, which is not simply "anything between the quotes" because you'd have to account for escaped quotes (possibly on many levels of nested strings).&lt;/P&gt;&lt;P&gt;But the more importantly - you'd have to reconstruct the json structure. While you have some json_*() functions, you have to know the structure beforehand to create/modify a json object. So if you can have anything in your "log" field... well, I don't see it working.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Apr 2022 18:43:34 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2022-04-21T18:43:34Z</dc:date>
    <item>
      <title>How to parse string JSON along with actual JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594713#M206992</link>
      <description>&lt;P&gt;I have the following log in Splunk:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "tags":{
        "app":"foobar",
        "ou":"internal"
    },
    "log":"{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}",
    "timestamp":"2022-04-21T17:00:00.000Z"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can parse the string JSON into actual JSON and replace the &lt;STRONG&gt;_raw&lt;/STRONG&gt; like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=my_index_name
| eval _raw=log&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, if I use the SPL above, the &lt;STRONG&gt;timestamp&lt;/STRONG&gt; and &lt;STRONG&gt;tags&lt;/STRONG&gt; keys would be deleted from the &lt;STRONG&gt;_raw&lt;/STRONG&gt;, that's not what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use SPL to parse it in a way where the &lt;STRONG&gt;_raw&lt;/STRONG&gt; equals to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "tags":{
        "app":"foobar",
        "ou":"internal"
    },
    "log": {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3"
    },
    "timestamp":"2022-04-21T17:00:00.000Z"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 17:52:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594713#M206992</guid>
      <dc:creator>JChris_</dc:creator>
      <dc:date>2022-04-21T17:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string JSON along with actual JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594714#M206993</link>
      <description>&lt;P&gt;Ok. So you have a json-formatted value inside your json event.&lt;/P&gt;&lt;P&gt;You can approach it from two different angles.&lt;/P&gt;&lt;P&gt;1) Explicitly use spath on that value.&lt;/P&gt;&lt;PRE&gt;&amp;lt;your_search&amp;gt;&lt;BR /&gt;| spath input=log&lt;/PRE&gt;&lt;P&gt;And I think it's the easiest solution.&lt;/P&gt;&lt;P&gt;2) "Rearrange" your event a bit - remember the old value of _raw, replace it, let Splunk parse it and then restore old _raw. A bit confusing, I know &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&amp;lt;your_search&amp;gt;&lt;BR /&gt;| eval oldraw=_raw&lt;BR /&gt;| eval _raw=log&lt;BR /&gt;| extract&lt;BR /&gt;| eval _raw=oldraw&lt;BR /&gt;| fields - oldraw&lt;/PRE&gt;&lt;P&gt;Haven't tried it but should work (but it's not a pretty solution).&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 18:09:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594714#M206993</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-04-21T18:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string JSON along with actual JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594716#M206995</link>
      <description>&lt;P&gt;I thought of using spath, it does work but does not override the _raw. I wanted the _raw to also be a complete JSON.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 18:29:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594716#M206995</guid>
      <dc:creator>JChris_</dc:creator>
      <dc:date>2022-04-21T18:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string JSON along with actual JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594719#M206996</link>
      <description>&lt;P&gt;Then you'd have to manipulate the event manually. Which could probably be possible in some specific cases but it'd be hard to do in general case. Firstly you'd have to remove the original contents of the field, which is not simply "anything between the quotes" because you'd have to account for escaped quotes (possibly on many levels of nested strings).&lt;/P&gt;&lt;P&gt;But the more importantly - you'd have to reconstruct the json structure. While you have some json_*() functions, you have to know the structure beforehand to create/modify a json object. So if you can have anything in your "log" field... well, I don't see it working.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 18:43:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594719#M206996</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-04-21T18:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string JSON along with actual JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594794#M207015</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval _raw=replace(_raw,"\\\\","")
| eval _raw=replace(_raw,"\"{","{")
| eval _raw=replace(_raw,"}\"","}")
| spath&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 22 Apr 2022 06:27:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-string-JSON-along-with-actual-JSON/m-p/594794#M207015</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-04-22T06:27:34Z</dc:date>
    </item>
  </channel>
</rss>

