<?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 extract field for statement. in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324607#M873</link>
    <description>&lt;P&gt;@jw44250, does the raw event contain only xml data? If so, you can set &lt;CODE&gt;KV_MODE=JSON&lt;/CODE&gt; in your props.conf. Refer to documentation: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath#Alternatives_to_the_spath_command"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath#Alternatives_to_the_spath_command&lt;/A&gt;. &lt;/P&gt;

&lt;P&gt;Also would it be possible for you to add complete JSON with sample/mocked up data? Are there multiple serialNumbers in single JSON or is there one serial number per JSON as in example from the question?&lt;/P&gt;

&lt;P&gt;You should explore the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;spath&lt;/A&gt; command for traversing JSON Data. Following is a run anywhere search based on one of them:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="{\"serialNumber\":\"test12836\",\"serviceChannel\":\"test\",\"countryOfPurchase\":\"ind\"}"
|  spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Apr 2018 02:54:28 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2018-04-10T02:54:28Z</dc:date>
    <item>
      <title>How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324600#M866</link>
      <description>&lt;P&gt;serialNumber":"test1234","serviceChannel":"test","countryOfPurchase":"US",&lt;/P&gt;

&lt;P&gt;serialNumber":"test1294","serviceChannel":"test","countryOfPurchase":"ind",&lt;/P&gt;

&lt;P&gt;serialNumber":"test12836","serviceChannel":"test","countryOfPurchase":"ind",&lt;/P&gt;

&lt;P&gt;serialNumber":"test125","serviceChannel":"test","countryOfPurchase":"chi",&lt;/P&gt;

&lt;P&gt;how filter &lt;/P&gt;

&lt;P&gt;serialNumber":"test1234"&lt;/P&gt;

&lt;P&gt;using row in splunk &lt;/P&gt;

&lt;P&gt;i have tried : but dint work &lt;/P&gt;

&lt;P&gt;rex field=_raw "(?serialNumber.*)"&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 19:37:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324600#M866</guid>
      <dc:creator>jw44250</dc:creator>
      <dc:date>2018-04-09T19:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324601#M867</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "serialNumber\":\"(?&amp;lt;serialNumber&amp;gt;\w*?)\""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Apr 2018 19:55:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324601#M867</guid>
      <dc:creator>kmaron</dc:creator>
      <dc:date>2018-04-09T19:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324602#M868</link>
      <description>&lt;P&gt;No result found&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 20:14:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324602#M868</guid>
      <dc:creator>jw44250</dc:creator>
      <dc:date>2018-04-09T20:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324603#M869</link>
      <description>&lt;P&gt;What do you mean no result found?  What is the rest of your search?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 20:23:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324603#M869</guid>
      <dc:creator>kmaron</dc:creator>
      <dc:date>2018-04-09T20:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324604#M870</link>
      <description>&lt;P&gt;index=text sourcetype=test | rex field=_raw "serialNumber\":\"(?\w*?)\"" |table serialNumber&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 20:45:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324604#M870</guid>
      <dc:creator>jw44250</dc:creator>
      <dc:date>2018-04-09T20:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324605#M871</link>
      <description>&lt;P&gt;it returns empty result.   it is in json format.&lt;/P&gt;

&lt;P&gt;{serialNumber":"test12836","serviceChannel":"test","countryOfPurchase":"ind",}&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 20:46:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324605#M871</guid>
      <dc:creator>jw44250</dc:creator>
      <dc:date>2018-04-09T20:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324606#M872</link>
      <description>&lt;P&gt;Hey jw44250,&lt;/P&gt;

&lt;P&gt;Try using this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "serialNumber\"\:\"(?P&amp;lt;SerialNumber&amp;gt;[^\"]+)\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if this helps!!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 02:40:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324606#M872</guid>
      <dc:creator>deepashri_123</dc:creator>
      <dc:date>2018-04-10T02:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324607#M873</link>
      <description>&lt;P&gt;@jw44250, does the raw event contain only xml data? If so, you can set &lt;CODE&gt;KV_MODE=JSON&lt;/CODE&gt; in your props.conf. Refer to documentation: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath#Alternatives_to_the_spath_command"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath#Alternatives_to_the_spath_command&lt;/A&gt;. &lt;/P&gt;

&lt;P&gt;Also would it be possible for you to add complete JSON with sample/mocked up data? Are there multiple serialNumbers in single JSON or is there one serial number per JSON as in example from the question?&lt;/P&gt;

&lt;P&gt;You should explore the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;spath&lt;/A&gt; command for traversing JSON Data. Following is a run anywhere search based on one of them:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="{\"serialNumber\":\"test12836\",\"serviceChannel\":\"test\",\"countryOfPurchase\":\"ind\"}"
|  spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 02:54:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324607#M873</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-10T02:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324608#M874</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;

&lt;P&gt;I am sure the answer given by @niketnilay should work but if you are looking to just extract serialNumber then you can go with the following query:&lt;/P&gt;

&lt;P&gt;Try this run anywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"serialNumber\":\"test12836\",\"serviceChannel\":\"test\",\"countryOfPurchase\":\"ind\"}" 
| rex "serialNumber\":\"(?&amp;lt;serialNumber&amp;gt;[^\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your environment, you should try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;base query&amp;gt; | rex "serialNumber\":\"(?&amp;lt;serialNumber&amp;gt;[^\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 05:05:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324608#M874</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-04-10T05:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324609#M875</link>
      <description>&lt;P&gt;Getting this below error &lt;BR /&gt;
Error in 'rex' command: Encountered the following error while compiling the regex 'serialNumber":"(?P[^"]+)"': Regex: unrecognized character after (?P&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 15:15:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324609#M875</guid>
      <dc:creator>jw44250</dc:creator>
      <dc:date>2018-04-10T15:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324610#M876</link>
      <description>&lt;P&gt;I want to run Ad hac command.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 15:16:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324610#M876</guid>
      <dc:creator>jw44250</dc:creator>
      <dc:date>2018-04-10T15:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324611#M877</link>
      <description>&lt;P&gt;My json:   searchBase | spath output=myfield path=test |table myfield&lt;/P&gt;

&lt;P&gt;The above query should work but not working..&lt;/P&gt;

&lt;P&gt;{&lt;BR /&gt;
   "foo" : {&lt;BR /&gt;
      "bar" : [&lt;BR /&gt;
         {"zoo" : 1},&lt;BR /&gt;
         {"baz" : 2}&lt;BR /&gt;
      ]&lt;BR /&gt;
   }&lt;BR /&gt;
   "test": 134&lt;BR /&gt;
},&lt;BR /&gt;
{&lt;BR /&gt;
   "foo" : {&lt;BR /&gt;
      "bar" : [&lt;BR /&gt;
         {"zoo" : 1},&lt;BR /&gt;
         {"baz" : 2}&lt;BR /&gt;
      ]&lt;BR /&gt;
   }&lt;BR /&gt;
   "test": 139&lt;BR /&gt;
}&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 16:58:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324611#M877</guid>
      <dc:creator>jw44250</dc:creator>
      <dc:date>2018-04-10T16:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324612#M878</link>
      <description>&lt;P&gt;When u have json and text together it ownt work &lt;/P&gt;

&lt;P&gt;This is my json from server .....&lt;BR /&gt;
{&lt;BR /&gt;
"foo" : {&lt;BR /&gt;
"bar" : [&lt;BR /&gt;
{"zoo" : 1},&lt;BR /&gt;
{"baz" : 2}&lt;BR /&gt;
]&lt;BR /&gt;
}&lt;BR /&gt;
"test": 134&lt;BR /&gt;
},&lt;BR /&gt;
{&lt;BR /&gt;
"foo" : {&lt;BR /&gt;
"bar" : [&lt;BR /&gt;
{"zoo" : 1},&lt;BR /&gt;
{"baz" : 2}&lt;BR /&gt;
]&lt;BR /&gt;
}&lt;BR /&gt;
"test": 139&lt;BR /&gt;
}&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 17:14:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324612#M878</guid>
      <dc:creator>jw44250</dc:creator>
      <dc:date>2018-04-10T17:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324613#M879</link>
      <description>&lt;P&gt;if you use an spath before the rex it should work.  (it does for me)&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 17:36:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324613#M879</guid>
      <dc:creator>kmaron</dc:creator>
      <dc:date>2018-04-10T17:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324614#M880</link>
      <description>&lt;P&gt;@jw44250, the JSON you have posted seems to be having incorrect structure (only first part can be traversed, Validate with any JSON Editor):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="{
\"foo\" : {
\"bar\" : [
{\"zoo\" : 1},
{\"baz\" : 2}
]
}
\"test\": 134
},
{
\"foo\" : {
\"bar\" : [
{\"zoo\" : 1},
{\"baz\" : 2}
]
}
\"test\": 139
}"
|  spath
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the correct structure for JSON&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="{
    \"test1\":{
        \"foo\" : {
            \"bar\" : [
                        {\"zoo\" : 1},
                        {\"baz\" : 2}
                    ]
            },
        \"test\": 134
    },
    \"test2\":{
        \"foo\" : {
            \"bar\" : [
                        {\"zoo\" : 1},
                        {\"baz\" : 2}
                    ]
            },
        \"test\": 139
    }
}"
|  spath
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If rectifying the JSON is out of question, you should use &lt;CODE&gt;rex&lt;/CODE&gt; to extract required field based on Regular Expression.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 05:49:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324614#M880</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-11T05:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324615#M881</link>
      <description>&lt;P&gt;Can you try the following rex if you need to extract the multi-valued &lt;CODE&gt;test&lt;/CODE&gt; field &lt;CODE&gt;|  rex "\"test\"\:\s(?&amp;lt;test&amp;gt;\d+)" max_match=0&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="{
\"foo\" : {
\"bar\" : [
{\"zoo\" : 1},
{\"baz\" : 2}
]
}
\"test\": 134
},
{
\"foo\" : {
\"bar\" : [
{\"zoo\" : 1},
{\"baz\" : 2}
]
}
\"test\": 139
}"
|  rex "\"test\"\:\s(?&amp;lt;test&amp;gt;\d+)" max_match=0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Apr 2018 05:52:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324615#M881</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-11T05:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324616#M882</link>
      <description>&lt;P&gt;I have edited my answer... can u try now?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 05:56:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324616#M882</guid>
      <dc:creator>deepashri_123</dc:creator>
      <dc:date>2018-04-11T05:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract field for statement.</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324617#M883</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;If you try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | makeresults | eval _raw="\"serialNumber\":\"test1234\",\"serviceChannel\":\"test\",\"countryOfPurchase\":\"US\""
    | rex field=_raw "\"serialNumber\":\"(?&amp;lt;serialNumber&amp;gt;\w*)"
    | table serialNumber
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In any case you can use Field Extractor UI &lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.3/Knowledge/ExtractfieldsinteractivelywithIFX"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.3/Knowledge/ExtractfieldsinteractivelywithIFX&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 09:31:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-extract-field-for-statement/m-p/324617#M883</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-11T09:31:54Z</dc:date>
    </item>
  </channel>
</rss>

