<?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 do search time extractions of nested json objects with props/transforms in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460506#M79486</link>
    <description>&lt;P&gt;Figured it out - I was trying too hard.  These entries in a props.conf, applied to events with sourcetype 'docker_line_extract' solved the problem. Still see the line. object in the search results, but the extracted fields appear in the fields list, and you can reference and/or build filters with the extracted fields as desired:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[docker_line_extract]
EXTRACT-line = (\{\"line\":\{)?\"(?&amp;lt;_KEY_1&amp;gt;[^=",]+)\":\s?\"?(?&amp;lt;_VAL_1&amp;gt;[^=",]*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Evidently leveraging the _KEY_1 and _VAL_1 convention will extract all the field/value pairs nested in the 'line' object.&lt;BR /&gt;
The &lt;CODE&gt;(\{\"line\":\{)?&lt;/CODE&gt; part at the start of the regex eliminates trying to extract and include an empty "line" field as well.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 04:46:57 GMT</pubDate>
    <dc:creator>jimbaxtermdi</dc:creator>
    <dc:date>2020-09-30T04:46:57Z</dc:date>
    <item>
      <title>How to do search time extractions of nested json objects with props/transforms</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460504#M79484</link>
      <description>&lt;P&gt;We have users migrating apps (that were using Universal Forwarders) to docker containers. The Splunk logging driver for docker embeds the logged json items inside a 'line' object as per the sanitized example below; these fields are not nested in 'line' when using a UF. There are a number of reports/dashboards/alerts built that won't work with the new logging solution because they're not expecting to have to reference a field with 'line.' - for example,  line.port  instead of just "port".  The desired goal is to extract the json fields out of 'line' and place them back in _raw so the reports/dashboards will work with either implementation.&lt;/P&gt;

&lt;P&gt;Example (simplified) event:&lt;/P&gt;

&lt;P&gt;{"line":{"_t":"2020-03-27T03:17:25.491296Z","logger":"some.logger","level":"INFO","env":"dev","port":"8000","process_id":51,"thread_id":140005384098624,"hostname":"964619888c0d"},"source":"stdout","tag":"some.instance.tag"}&lt;/P&gt;

&lt;P&gt;I'm trying to build a props/transforms solution that extracts the json out of 'line' and places those fields back at the '_raw' event level. Here's what I have so far:&lt;/P&gt;

&lt;P&gt;local.meta&lt;BR /&gt;
[]&lt;BR /&gt;
export = system&lt;/P&gt;

&lt;P&gt;props.conf&lt;BR /&gt;
[docker_line_extract]&lt;BR /&gt;
REPORT-line = extract_line_object, extract_line_objects&lt;/P&gt;

&lt;P&gt;transforms.conf&lt;BR /&gt;
[extract_line_object]&lt;BR /&gt;
REGEX = {\"line\":{(?.*)},&lt;/P&gt;

&lt;P&gt;[extract_line_objects]&lt;BR /&gt;
REGEX = \"(?&amp;lt;_KEY_1&amp;gt;[^="\]+)\":\s?\"?(?&amp;lt;_VAL_1&amp;gt;[^="\]*)&lt;BR /&gt;
FORMAT = $1::$2&lt;BR /&gt;
SOURCE_KEY = field:lineobj&lt;BR /&gt;
DEST_KEY = _raw&lt;BR /&gt;
REPEAT_MATCH = true&lt;/P&gt;

&lt;P&gt;The above succeeds in extracting the json field/values out of 'line' - the 'lineobj' field appears in the fields list in Splunk Web; clicking one reveals the expected content: "_t":"2020-03-27T03:17:25.491296Z","logger":"some.logger","level":"INFO","env":"dev","port":"8000","process_id":51,"thread_id":140005384098624,"hostname":"964619888c0d"&lt;/P&gt;

&lt;P&gt;So that part is working. But I can't seem to get the json field/values extracted out of 'lineobj' and placed in the _raw event as desired - tried a lot of variations, no luck. Does anyone have some insights / solution?  Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:46:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460504#M79484</guid>
      <dc:creator>jimbaxtermdi</dc:creator>
      <dc:date>2020-09-30T04:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to do search time extractions of nested json objects with props/transforms</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460505#M79485</link>
      <description>&lt;P&gt;Correction to transforms.conf - should have used the code block the first time - apologies:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[extract_line_object]
REGEX = \{\"line\":\{(?&amp;lt;lineobj&amp;gt;.*)\},

[extract_line_objects]
REGEX = \"(?&amp;lt;_KEY_1&amp;gt;[^="\\]+)\":\s?\"?(?&amp;lt;_VAL_1&amp;gt;[^="\\]*)
FORMAT = $1::$2
SOURCE_KEY = field:lineobj
DEST_KEY = _raw
REPEAT_MATCH = true
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Mar 2020 19:53:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460505#M79485</guid>
      <dc:creator>jimbaxtermdi</dc:creator>
      <dc:date>2020-03-27T19:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to do search time extractions of nested json objects with props/transforms</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460506#M79486</link>
      <description>&lt;P&gt;Figured it out - I was trying too hard.  These entries in a props.conf, applied to events with sourcetype 'docker_line_extract' solved the problem. Still see the line. object in the search results, but the extracted fields appear in the fields list, and you can reference and/or build filters with the extracted fields as desired:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[docker_line_extract]
EXTRACT-line = (\{\"line\":\{)?\"(?&amp;lt;_KEY_1&amp;gt;[^=",]+)\":\s?\"?(?&amp;lt;_VAL_1&amp;gt;[^=",]*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Evidently leveraging the _KEY_1 and _VAL_1 convention will extract all the field/value pairs nested in the 'line' object.&lt;BR /&gt;
The &lt;CODE&gt;(\{\"line\":\{)?&lt;/CODE&gt; part at the start of the regex eliminates trying to extract and include an empty "line" field as well.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:46:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460506#M79486</guid>
      <dc:creator>jimbaxtermdi</dc:creator>
      <dc:date>2020-09-30T04:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to do search time extractions of nested json objects with props/transforms</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460507#M79487</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{\"line\":{\"_t\":\"2020-03-27T03:17:25.491296Z\",\"logger\":\"some.logger\",\"level\":\"INFO\",\"env\":\"dev\",\"port\":\"8000\",\"process_id\":51,\"thread_id\":140005384098624,\"hostname\":\"964619888c0d\"},\"source\":\"stdout\",\"tag\":\"some.instance.tag\"}"
| rex mode=sed "s/{.*({.*}).*}/\1/"
| spath
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;spath&lt;/CODE&gt; works. &lt;BR /&gt;
props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[docker_line_extract]
SEDCMD-trim_line = s/{.*({.*}).*}/\1/
KV_MODE = json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can use &lt;CODE&gt;KV_MODE&lt;/CODE&gt; , not need other field extraction.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 23:07:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460507#M79487</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-27T23:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to do search time extractions of nested json objects with props/transforms</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460508#M79488</link>
      <description>&lt;P&gt;And, of course you can add this under a [default] stanza in props.conf if you need it to be applied to any sourcetype:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[default]
EXTRACT-line = (\{\"line\":\{)?\"(?&amp;lt;_KEY_1&amp;gt;[^=",]+)\":\s?\"?(?&amp;lt;_VAL_1&amp;gt;[^=",]*)

[other_sourcetypes]
...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Mar 2020 19:54:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-do-search-time-extractions-of-nested-json-objects-with/m-p/460508#M79488</guid>
      <dc:creator>jimbaxtermdi</dc:creator>
      <dc:date>2020-03-30T19:54:52Z</dc:date>
    </item>
  </channel>
</rss>

