<?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: Extract fields from Json from selected log and use it as table column in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608438#M211548</link>
    <description>&lt;P&gt;Sorry, I need to rephrase my question. For Log, not&amp;nbsp; every one of them is standard JSON, some of them are just a string, and sometimes the Log is a totally different structure of Json&lt;/P&gt;</description>
    <pubDate>Fri, 05 Aug 2022 12:42:40 GMT</pubDate>
    <dc:creator>rnach</dc:creator>
    <dc:date>2022-08-05T12:42:40Z</dc:date>
    <item>
      <title>How to extract fields from Json from selected log and use it as table column?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608363#M211523</link>
      <description>&lt;P&gt;Hi all, I am new to Splunk. Right now I am trying to make a table out of a log, which contains different fields like Level = INFO etc., there's a field&amp;nbsp;&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; Log = {"objects":[object1, object2 ...], "info": "some strings", "id1": someInt, "id2": someInt} 

Log = {"objects":[object1, object2 ...], "info": "some other strings", "id1": someOtherInt, "id2": someOtherInt} 

Log = { "info": "some log strings"} 

Log = "some string"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried a few rex and spath but it seems that it's not working well&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I would like to extract "objects" field by different "info", for example, I need objects from Log but sometimes I need objects from the first Log above, and sometimes I need them from second Log ( for different panels in dashboard), and the way to separate them is by using "info"&lt;BR /&gt;And need to display objects in it in a chart under a column. Any help/hints are appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 14:32:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608363#M211523</guid>
      <dc:creator>rnach</dc:creator>
      <dc:date>2022-08-05T14:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Extract fields from Json from selected log and use it as table column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608368#M211525</link>
      <description>&lt;P&gt;Regex should be the last thing to try when extracting information from a structured data set. &amp;nbsp;Use&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath" target="_blank" rel="noopener"&gt;spath&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=Log&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Log&lt;/TD&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;id2&lt;/TD&gt;&lt;TD&gt;info&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;objects{}&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;{"objects":["object1", "object2"], "info": "some strings", "id1": "someInt", "id2": "someInt"}&lt;/TD&gt;&lt;TD&gt;someInt&lt;/TD&gt;&lt;TD&gt;someInt&lt;/TD&gt;&lt;TD&gt;some strings&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;object1&lt;/DIV&gt;&lt;DIV class=""&gt;object2&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;{"objects":["object1", "object2", "object3"], "info": "some other strings", "id1": "someOtherInt", "id2": "someOtherInt"}&lt;/TD&gt;&lt;TD&gt;someOtherInt&lt;/TD&gt;&lt;TD&gt;someOtherInt&lt;/TD&gt;&lt;TD&gt;some other strings&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;object1&lt;/DIV&gt;&lt;DIV class=""&gt;object2&lt;/DIV&gt;&lt;DIV class=""&gt;object3&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;{ "info": "some log strings"}&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;some log strings&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 05 Aug 2022 02:26:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608368#M211525</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-08-05T02:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract fields from Json from selected log and use it as table column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608438#M211548</link>
      <description>&lt;P&gt;Sorry, I need to rephrase my question. For Log, not&amp;nbsp; every one of them is standard JSON, some of them are just a string, and sometimes the Log is a totally different structure of Json&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 12:42:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608438#M211548</guid>
      <dc:creator>rnach</dc:creator>
      <dc:date>2022-08-05T12:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Extract fields from Json from selected log and use it as table column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608581#M211617</link>
      <description>&lt;P&gt;In that case, you will need to define how Splunk should behave first. &amp;nbsp;For example, from the line where Log = "Some string", do you expect some use? &amp;nbsp;Such lines will simply give null values for info, objects{}, etc.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_raw&lt;/TD&gt;&lt;TD&gt;_time&lt;/TD&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;id2&lt;/TD&gt;&lt;TD&gt;info&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;objects{}&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Log = {"objects":["object1", "object2"], "info": "some strings", "id1": "someInt", "id2": "someInt"}&lt;/TD&gt;&lt;TD&gt;2022-08-05 23:41:37&lt;/TD&gt;&lt;TD&gt;someInt&lt;/TD&gt;&lt;TD&gt;someInt&lt;/TD&gt;&lt;TD&gt;some strings&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;object1&lt;/DIV&gt;&lt;DIV class=""&gt;object2&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Log = {"objects":["object1", "object2", "object3"], "info": "some other strings", "id1": "someOtherInt", "id2": "someOtherInt"}&lt;/TD&gt;&lt;TD&gt;2022-08-05 23:41:37&lt;/TD&gt;&lt;TD&gt;someOtherInt&lt;/TD&gt;&lt;TD&gt;someOtherInt&lt;/TD&gt;&lt;TD&gt;some other strings&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;object1&lt;/DIV&gt;&lt;DIV class=""&gt;object2&lt;/DIV&gt;&lt;DIV class=""&gt;object3&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Log = { "info": "some log strings"}&lt;/TD&gt;&lt;TD&gt;2022-08-05 23:41:37&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;some log strings&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Log = "some string"&lt;/TD&gt;&lt;TD&gt;2022-08-05 23:41:37&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Based on your original description, the objective is really just to operate on those two fields.&lt;/P&gt;&lt;P&gt;After spath, you can definitely select objects{} from whichever &lt;FONT face="andale mono,times"&gt;info&lt;/FONT&gt; value. &amp;nbsp;For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=Log
| where info == "some strings"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;will give&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_raw&lt;/TD&gt;&lt;TD&gt;_time&lt;/TD&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;id2&lt;/TD&gt;&lt;TD&gt;info&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;objects{}&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Log = {"objects":["object1", "object2"], "info": "some strings", "id1": "someInt", "id2": "someInt"}&lt;/TD&gt;&lt;TD&gt;2022-08-05 23:41:37&lt;/TD&gt;&lt;TD&gt;someInt&lt;/TD&gt;&lt;TD&gt;someInt&lt;/TD&gt;&lt;TD&gt;some strings&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;object1&lt;/DIV&gt;&lt;DIV class=""&gt;object2&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=Log
| where info == "some other strings"​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gives&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_raw&lt;/TD&gt;&lt;TD&gt;_time&lt;/TD&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;id2&lt;/TD&gt;&lt;TD&gt;info&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;objects{}&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Log = {"objects":["object1", "object2", "object3"], "info": "some other strings", "id1": "someOtherInt", "id2": "someOtherInt"}&lt;/TD&gt;&lt;TD&gt;2022-08-05 23:41:37&lt;/TD&gt;&lt;TD&gt;someOtherInt&lt;/TD&gt;&lt;TD&gt;someOtherInt&lt;/TD&gt;&lt;TD&gt;some other strings&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;object1&lt;/DIV&gt;&lt;DIV class=""&gt;object2&lt;/DIV&gt;&lt;DIV class=""&gt;object3&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;Is that what you described?&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 06:57:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608581#M211617</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-08-06T06:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extract fields from Json from selected log and use it as table column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608589#M211620</link>
      <description>&lt;P&gt;Yes, thank you! Thank you that works very well. As you mentioned, I do expect some use. For example, if I want to display the _time in a column where&amp;nbsp;&lt;SPAN&gt;"some strings" and _time in another column where&amp;nbsp;"some other strings" in a chart(essentially the time range of two Logs). I tried use spath twice in the search but it seems that values are not returned correctly while "info" is different strings.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 23:44:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608589#M211620</guid>
      <dc:creator>rnach</dc:creator>
      <dc:date>2022-08-06T23:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extract fields from Json from selected log and use it as table column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608595#M211624</link>
      <description>&lt;P&gt;OK, so those events in which Log do not equal to a valid JSON do not matter. &amp;nbsp;Your requirements are&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Extract fields such as "info" from JSON.&lt;/LI&gt;&lt;LI&gt;Use field value as new column name.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The first is achieved by spath. &amp;nbsp;I haven't found a general approach to the second. &amp;nbsp;However, if you can enumerate values of info, here is a cheat:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=Log
| foreach "some strings" "some other strings" "some log strings"
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = if(info == "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", _time, null()) ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Alternatively, if you only want to tabulate _time by info value,&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=Log
| table _time info
| transpose header_field=info&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 07 Aug 2022 08:37:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608595#M211624</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-08-07T08:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: Extract fields from Json from selected log and use it as table column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608597#M211625</link>
      <description>&lt;P&gt;Oh, sorry for any confusion. I am not trying to use values as column name rather than values.&lt;/P&gt;&lt;P&gt;What I’m trying to do here is to find the time stamp of log with certain info( for example: some strings) and find the time stamp of another log with certain info( for example, some other strings) and trying to display the duration in between. After spath, i have something like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;| eval session_start=if(searchmatch("some string"),min(_time),null()) 
| eval session_end=if(searchmatch("some other string"),max(_time),null())&lt;BR /&gt;| stats values(session_start) as start, values(session_end) as end | eval Duration= end-start | table Duration start end&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;But it's not displaying the duration, but session_start and session_end are correct if I put them under table, trying to calculate diff but it seems that it's not calculating.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update:&amp;nbsp;&lt;BR /&gt;I figured it out&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| eval session_start=if(searchmatch("some string"),_time,null()) 
| eval session_end=if(searchmatch("some other string"),_time,null())&lt;BR /&gt;| stats values(session_start) as ss, values(session_end) as se | eval dur=se-ss | table dur&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 00:30:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608597#M211625</guid>
      <dc:creator>rnach</dc:creator>
      <dc:date>2022-08-08T00:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extract fields from Json from selected log and use it as table column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608632#M211638</link>
      <description>&lt;P&gt;You just invented&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction" target="_blank" rel="noopener"&gt;transaction&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;. &amp;nbsp;For reference, you can achieve the same with something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction startswith=eval(info=="some strings") endswith=eval(info=="some otherstrings")
| table duration&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But transaction is expensive. &amp;nbsp;Using stats is usually preferred.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 06:03:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-Json-from-selected-log-and-use-it-as/m-p/608632#M211638</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-08-08T06:03:22Z</dc:date>
    </item>
  </channel>
</rss>

