<?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: In a JSON Payload, parse out \n to newline in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463290#M130607</link>
    <description>&lt;P&gt;&lt;CODE&gt;| eval log=split(replace(log,"(?ms)\\\n","#"),"#")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If you want to solve the problem, see what the query is doing.&lt;BR /&gt;
The respondent is not your subcontractor.&lt;/P&gt;</description>
    <pubDate>Thu, 28 May 2020 20:38:48 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-05-28T20:38:48Z</dc:date>
    <item>
      <title>In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463280#M130597</link>
      <description>&lt;P&gt;Hi! I'm trying to see if I can get a JSON Payload like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"log":"2020-05-28 06:52:34,671 GMT TRACE [com.xxx.oss.core.servlets.TransactionFilter] (http-nio-8080-exec-7|R:lB6-JwrDGgR-ZvKy|ThreadId=55|ThreadPriority=5) Responding with outbound response: HTTP 200\\ncontent-length: 85\\ncontent-type: application/json\\n\\n{\"results\":true,\"internalTransactionId\":\"lB6-JwrDGgR-ZvKy\",\"executionTimeInMillis\":0}\n","container_name":"idm-geoservices","namespace_name":"dev","host":"server"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To replace where I have a literal "\n", and present it as a New Line and also represent the JSON payload in the pretty JSON format, if possible.&lt;/P&gt;

&lt;P&gt;I have tried something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval log=replace(log,"\\\\n","[\n]")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can get the replacement to show when I do something like "TEST", but what I really want to do is have the "log" field present the \n in the message as a new line.&lt;/P&gt;

&lt;P&gt;Longer term, we're going to implement Splunk Connect for Kubernetes, but we're trying to get our user taken care of with being able to parse out a multi-line JSON message from Kubernetes.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;BR /&gt;
Stephen&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 07:32:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463280#M130597</guid>
      <dc:creator>skirven</dc:creator>
      <dc:date>2020-05-28T07:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463281#M130598</link>
      <description>&lt;P&gt;Hi @skirven,&lt;/P&gt;

&lt;P&gt;If you just want to present that JSON in a nicer format then your only option is probably the makemv command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makemv delim="\\\\n" yourfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As in the following screenshot. I know is not ideal, as you are creating a multivalue field, but it is presented in a much more readable way so hopefully it'll help.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8977i9FC1ACD97F174B2E/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Or you could also use spath to extract the fields and then apply makemv to log:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8978i9127B7D2B8E91BF6/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Let me know if that helps.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 08:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463281#M130598</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2020-05-28T08:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463282#M130599</link>
      <description>&lt;P&gt;You can update the field with something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;base search&amp;gt;| rex field=log mode=sed "s/\\\n/\n/g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However that does not change the shown event, it only updates the field (visualise it with &lt;CODE&gt;| table log&lt;/CODE&gt; for example).&lt;/P&gt;

&lt;P&gt;To do it at index-time, make changes to props.conf like below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype]
SEDCMD-newline= s/\\\n/\n/g
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 08:01:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463282#M130599</guid>
      <dc:creator>Patrick_Peeters</dc:creator>
      <dc:date>2020-05-28T08:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463283#M130600</link>
      <description>&lt;P&gt;@javiergn - That actually didn't get anything parsed? &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 08:19:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463283#M130600</guid>
      <dc:creator>skirven</dc:creator>
      <dc:date>2020-05-28T08:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463284#M130601</link>
      <description>&lt;P&gt;@ppeeters_splunk - Hi! I actually have tried that too, and it didn't work. &lt;/P&gt;

&lt;P&gt;I think this also mirrors the test case, and it's not parsing out what I was hoping. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval _raw="{\"log\":\"2020-05-28 06:52:34,671 GMT TRACE [com.xxx.oss.core.servlets.TransactionFilter] (http-nio-8080-exec-7|R:lB6-JwrDGgR-ZvKy|ThreadId=55|ThreadPriority=5) Responding with outbound response: HTTP 200\\ncontent-length: 85\\ncontent-type: application/json\\n\\n{\"results\":true,\"internalTransactionId\":\"lB6-JwrDGgR-ZvKy\",\"executionTimeInMillis\":0}\n\",\"container_name\":\"idm-geoservices\",\"namespace_name\":\"dev\",\"host\":\"server\"}" | rex field=log mode=sed "s/\\\n/\n/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 08:20:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463284#M130601</guid>
      <dc:creator>skirven</dc:creator>
      <dc:date>2020-05-28T08:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463285#M130602</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"log\":\"2020-05-28 06:52:34,671 GMT TRACE [com.xxx.oss.core.servlets.TransactionFilter] (http-nio-8080-exec-7|R:lB6-JwrDGgR-ZvKy|ThreadId=55|ThreadPriority=5) Responding with outbound response: HTTP 200\\ncontent-length: 85\\ncontent-type: application/json\\n\\n{\"results\":true,\"internalTransactionId\":\"lB6-JwrDGgR-ZvKy\",\"executionTimeInMillis\":0}\n\",\"container_name\":\"idm-geoservices\",\"namespace_name\":\"dev\",\"host\":\"server\"}"
| rex "(?ms)log\":\"(?&amp;lt;log&amp;gt;.*?\})"
| eval log=split(replace(log,"(?ms)\\\n","#"),"#")
| rex mode=sed "s/{.*?}[^,]+,(.*)/{\1/"
| spath
| eval _raw=mvindex(log,4)
| spath
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That's a lot of work.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 09:08:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463285#M130602</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-05-28T09:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463286#M130603</link>
      <description>&lt;P&gt;Sorry what didn't get anything parsed?&lt;BR /&gt;
This?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makemv delim="\\\\n" yourfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What's your fieldname? Is it _raw? If so then use it like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makemv delim="\\\\n" _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can also extract our JSON fields first with spath, as in the second screenshot, and then use makemv against the one containing the new lines (log in this case).&lt;/P&gt;

&lt;P&gt;In any case, it always helps if you paste query here.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 09:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463286#M130603</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2020-05-28T09:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463287#M130604</link>
      <description>&lt;P&gt;Yes. That's a lot of work, and seems highly tailored to the one result. The problem I'm really just wanting to solve is to replace the "\n" with a normal regex \n and show the new line.&lt;/P&gt;

&lt;P&gt;When the string was parsed with other data, it didn't represent the rest of the lines correctly. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;
Thanks!&lt;BR /&gt;
Stephen&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 10:06:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463287#M130604</guid>
      <dc:creator>skirven</dc:creator>
      <dc:date>2020-05-28T10:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463288#M130605</link>
      <description>&lt;P&gt;Ah ok, in my case I had already used &lt;CODE&gt;sourcetype=_json&lt;/CODE&gt; when indexing the data. In that case you can use &lt;CODE&gt;| rex field=_raw mode=sed "s/\\\n/\n/g"&lt;/CODE&gt; as there is no log field.&lt;/P&gt;

&lt;P&gt;It won't make it pretty JSON format though, just show the event slightly better. The issue you'll have is that the &lt;CODE&gt;log&lt;/CODE&gt; field is not proper JSON in the first place, it's just a long string. You might get it to work with some regex trickery or in a complex way but you might be better off seeing if you can get the source data properly formatted first.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 10:10:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463288#M130605</guid>
      <dc:creator>Patrick_Peeters</dc:creator>
      <dc:date>2020-05-28T10:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463289#M130606</link>
      <description>&lt;P&gt;Looking at this solution closer, I actually proposed this solution to the user, and awaiting feedback. What I didn't think of was just dropping it into a table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makemv delim="\\n" log | table _time, log
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 10:23:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463289#M130606</guid>
      <dc:creator>skirven</dc:creator>
      <dc:date>2020-05-28T10:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463290#M130607</link>
      <description>&lt;P&gt;&lt;CODE&gt;| eval log=split(replace(log,"(?ms)\\\n","#"),"#")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If you want to solve the problem, see what the query is doing.&lt;BR /&gt;
The respondent is not your subcontractor.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 20:38:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463290#M130607</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-05-28T20:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: In a JSON Payload, parse out \n to newline</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463291#M130608</link>
      <description>&lt;P&gt;This worked! Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 20:51:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-a-JSON-Payload-parse-out-n-to-newline/m-p/463291#M130608</guid>
      <dc:creator>skirven</dc:creator>
      <dc:date>2020-05-28T20:51:45Z</dc:date>
    </item>
  </channel>
</rss>

