<?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 Extracting field from JSON and XML response in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42784#M10043</link>
    <description>&lt;P&gt;Depending on the content-type, the response that is logged is either in JSON or XML. I want to create a single query that would extract the REQUEST and DETAIL regardless of what the content-type is. I'm thinking I'd have to use spath, but I'm having a hard time grabbing the response between the "------------" and "&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;". I tried escaping it but no luck. Any help would be appreciated.&lt;/P&gt;

&lt;P&gt;Note that these are 2 different log events.&lt;/P&gt;

&lt;P&gt;2013-02-23 22:36:11,900 ID=[12345] &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;gt; HTTP STATUS (400) POST &lt;A href="https://myapi/test" target="_blank"&gt;https://myapi/test&lt;/A&gt; &amp;gt; content-type: application/xml &amp;gt; accept: application/xml &amp;gt; host: test.com &amp;gt; content-length: 249 &amp;gt; connection: Keep-Alive &amp;gt; &amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;STRONG&gt;&lt;REQUEST&gt;&lt;FIRSTNAME&gt;john&lt;/FIRSTNAME&gt;&lt;LASTNAME&gt;doe&lt;/LASTNAME&gt;&lt;ID&gt;12345&lt;/ID&gt;&lt;/REQUEST&gt;&lt;/STRONG&gt; ++++++++++ &amp;gt; Content-Type: application/xml &amp;gt; Cache-Control: no-cache, no-transform &amp;gt; = &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt; &lt;ERROR&gt; &lt;STATUS&gt;400&lt;/STATUS&gt; &lt;SOURCE&gt;myapi&lt;/SOURCE&gt; &lt;CODE&gt;INVALID_LASTNAME&lt;/CODE&gt; &lt;DETAIL&gt; &lt;TYPE&gt;TEST&lt;/TYPE&gt; &lt;ANNOTATION&gt;EXPECTED: LENGTH TOO SHORT&lt;/ANNOTATION&gt; &lt;/DETAIL&gt; &lt;/ERROR&gt; ------------ &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt; &lt;ERROR&gt; &lt;STATUS&gt;400&lt;/STATUS&gt; &lt;SOURCE&gt;myapi&lt;/SOURCE&gt; &lt;CODE&gt;INVALID_LASTNAME&lt;/CODE&gt; &lt;STRONG&gt;&lt;DETAIL&gt; &lt;TYPE&gt;TEST&lt;/TYPE&gt; &lt;ANNOTATION&gt;EXPECTED: LENGTH TOO SHORT&lt;/ANNOTATION&gt; &lt;/DETAIL&gt;&lt;/STRONG&gt; &lt;/ERROR&gt; &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/P&gt;

&lt;P&gt;2013-02-23 22:36:11,900 ID=[12345] &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;gt; HTTP STATUS (400) POST &lt;A href="https://myapi/test" target="_blank"&gt;https://myapi/test&lt;/A&gt; &amp;gt; content-type: application/json; charset=utf-8 &amp;gt; accept: application/json &amp;gt; host: test.com &amp;gt; content-length: 74 &amp;gt; Expect: 100-continue &amp;gt; connection: Keep-Alive &amp;gt; &lt;STRONG&gt;{"firstname":"john","lastname":"doe","id":"12345"}&lt;/STRONG&gt; ++++++++++ &amp;gt; Content-Type: application/json &amp;gt; Cache-Control: no-cache, no-transform &amp;gt; = { "status" : 400, "source" : "myapi", "code" : "INVALID_LASTNAME", "detail" : [ { "type" : "TEST", "annotation" : "EXPECTED: LENGTH TOO SHORT" } ] } ------------ { "status" : 400, "source" : "myapi", "code" : "INVALID_LASTNAME", &lt;STRONG&gt;"detail" : [ { "type" : "TEST", "annotation" : "EXPECTED: LENGTH TOO SHORT" } ]&lt;/STRONG&gt; } &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 13:23:18 GMT</pubDate>
    <dc:creator>dbautist</dc:creator>
    <dc:date>2020-09-28T13:23:18Z</dc:date>
    <item>
      <title>Extracting field from JSON and XML response</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42784#M10043</link>
      <description>&lt;P&gt;Depending on the content-type, the response that is logged is either in JSON or XML. I want to create a single query that would extract the REQUEST and DETAIL regardless of what the content-type is. I'm thinking I'd have to use spath, but I'm having a hard time grabbing the response between the "------------" and "&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;". I tried escaping it but no luck. Any help would be appreciated.&lt;/P&gt;

&lt;P&gt;Note that these are 2 different log events.&lt;/P&gt;

&lt;P&gt;2013-02-23 22:36:11,900 ID=[12345] &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;gt; HTTP STATUS (400) POST &lt;A href="https://myapi/test" target="_blank"&gt;https://myapi/test&lt;/A&gt; &amp;gt; content-type: application/xml &amp;gt; accept: application/xml &amp;gt; host: test.com &amp;gt; content-length: 249 &amp;gt; connection: Keep-Alive &amp;gt; &amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;STRONG&gt;&lt;REQUEST&gt;&lt;FIRSTNAME&gt;john&lt;/FIRSTNAME&gt;&lt;LASTNAME&gt;doe&lt;/LASTNAME&gt;&lt;ID&gt;12345&lt;/ID&gt;&lt;/REQUEST&gt;&lt;/STRONG&gt; ++++++++++ &amp;gt; Content-Type: application/xml &amp;gt; Cache-Control: no-cache, no-transform &amp;gt; = &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt; &lt;ERROR&gt; &lt;STATUS&gt;400&lt;/STATUS&gt; &lt;SOURCE&gt;myapi&lt;/SOURCE&gt; &lt;CODE&gt;INVALID_LASTNAME&lt;/CODE&gt; &lt;DETAIL&gt; &lt;TYPE&gt;TEST&lt;/TYPE&gt; &lt;ANNOTATION&gt;EXPECTED: LENGTH TOO SHORT&lt;/ANNOTATION&gt; &lt;/DETAIL&gt; &lt;/ERROR&gt; ------------ &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt; &lt;ERROR&gt; &lt;STATUS&gt;400&lt;/STATUS&gt; &lt;SOURCE&gt;myapi&lt;/SOURCE&gt; &lt;CODE&gt;INVALID_LASTNAME&lt;/CODE&gt; &lt;STRONG&gt;&lt;DETAIL&gt; &lt;TYPE&gt;TEST&lt;/TYPE&gt; &lt;ANNOTATION&gt;EXPECTED: LENGTH TOO SHORT&lt;/ANNOTATION&gt; &lt;/DETAIL&gt;&lt;/STRONG&gt; &lt;/ERROR&gt; &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/P&gt;

&lt;P&gt;2013-02-23 22:36:11,900 ID=[12345] &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;gt; HTTP STATUS (400) POST &lt;A href="https://myapi/test" target="_blank"&gt;https://myapi/test&lt;/A&gt; &amp;gt; content-type: application/json; charset=utf-8 &amp;gt; accept: application/json &amp;gt; host: test.com &amp;gt; content-length: 74 &amp;gt; Expect: 100-continue &amp;gt; connection: Keep-Alive &amp;gt; &lt;STRONG&gt;{"firstname":"john","lastname":"doe","id":"12345"}&lt;/STRONG&gt; ++++++++++ &amp;gt; Content-Type: application/json &amp;gt; Cache-Control: no-cache, no-transform &amp;gt; = { "status" : 400, "source" : "myapi", "code" : "INVALID_LASTNAME", "detail" : [ { "type" : "TEST", "annotation" : "EXPECTED: LENGTH TOO SHORT" } ] } ------------ { "status" : 400, "source" : "myapi", "code" : "INVALID_LASTNAME", &lt;STRONG&gt;"detail" : [ { "type" : "TEST", "annotation" : "EXPECTED: LENGTH TOO SHORT" } ]&lt;/STRONG&gt; } &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:23:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42784#M10043</guid>
      <dc:creator>dbautist</dc:creator>
      <dc:date>2020-09-28T13:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting field from JSON and XML response</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42785#M10044</link>
      <description>&lt;P&gt;I was bored...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 increment=5m | head 2 | eval tmp = if(starttime%600==0,"2013-02-23 22:36:11,900 ID=[12345] &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;gt; HTTP STATUS (400) POST &lt;A href="https://myapi/test" target="test_blank"&gt;https://myapi/test&lt;/A&gt; &amp;gt; content-type: application/xml &amp;gt; accept: application/xml &amp;gt; host: test.com &amp;gt; content-length: 249 &amp;gt; connection: Keep-Alive &amp;gt; &amp;lt;?xml version=\"1.0\" encoding=\"utf-8\"?&amp;gt;&amp;lt;request&amp;gt;&amp;lt;firstname&amp;gt;john&amp;lt;/firstname&amp;gt;&amp;lt;lastname&amp;gt;doe&amp;lt;/lastname&amp;gt;&amp;lt;id&amp;gt;12345&amp;lt;/id&amp;gt;&amp;lt;/request&amp;gt; ++++++++++ &amp;gt; Content-Type: application/xml &amp;gt; Cache-Control: no-cache, no-transform &amp;gt; = &amp;lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&amp;gt; &amp;lt;error&amp;gt; &amp;lt;status&amp;gt;400&amp;lt;/status&amp;gt; &amp;lt;source&amp;gt;myapi&amp;lt;/source&amp;gt; &amp;lt;code&amp;gt;INVALID_LASTNAME&amp;lt;/code&amp;gt; &amp;lt;detail&amp;gt; &amp;lt;type&amp;gt;TEST&amp;lt;/type&amp;gt; &amp;lt;annotation&amp;gt;EXPECTED: LENGTH TOO SHORT&amp;lt;/annotation&amp;gt; &amp;lt;/detail&amp;gt; &amp;lt;/error&amp;gt; ------------ &amp;lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&amp;gt; &amp;lt;error&amp;gt; &amp;lt;status&amp;gt;400&amp;lt;/status&amp;gt; &amp;lt;source&amp;gt;myapi&amp;lt;/source&amp;gt; &amp;lt;code&amp;gt;INVALID_LASTNAME&amp;lt;/code&amp;gt; &amp;lt;detail&amp;gt; &amp;lt;type&amp;gt;TEST&amp;lt;/type&amp;gt; &amp;lt;annotation&amp;gt;EXPECTED: LENGTH TOO SHORT&amp;lt;/annotation&amp;gt; &amp;lt;/detail&amp;gt; &amp;lt;/error&amp;gt; &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;","2013-02-23 22:36:11,900 ID=[12345] &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;gt; HTTP STATUS (400) POST &lt;A href="https://myapi/test" target="test_blank"&gt;https://myapi/test&lt;/A&gt; &amp;gt; content-type: application/json; charset=utf-8 &amp;gt; accept: application/json &amp;gt; host: test.com &amp;gt; content-length: 74 &amp;gt; Expect: 100-continue &amp;gt; connection: Keep-Alive &amp;gt; {\"firstname\":\"john\",\"lastname\":\"doe\",\"id\":\"12345\"} ++++++++++ &amp;gt; Content-Type: application/json &amp;gt; Cache-Control: no-cache, no-transform &amp;gt; = { \"status\" : 400, \"source\" : \"myapi\", \"code\" : \"INVALID_LASTNAME\", \"detail\" : [ { \"type\" : \"TEST\", \"annotation\" : \"EXPECTED: LENGTH TOO SHORT\" } ] } ------------ { \"status\" : 400, \"source\" : \"myapi\", \"code\" : \"INVALID_LASTNAME\", \"detail\" : [ { \"type\" : \"TEST\", \"annotation\" : \"EXPECTED: LENGTH TOO SHORT\" } ] } &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;") | rex field=tmp "(?&amp;lt;req_xml&amp;gt;\&amp;lt;\?xml .+?)\s+\+{8}.*?-{8,}\s+(?&amp;lt;resp_xml&amp;gt;\&amp;lt;\?xml .*?)\s+\&amp;lt;{8,}" | rex field=tmp "\&amp;gt;\s+(?&amp;lt;req_json&amp;gt;\{.*?)\s+\+{8,}.*?-{8,}\s+(?&amp;lt;resp_json&amp;gt;\{.*?)\s+\&amp;lt;{8,}" | spath input=req_xml output=firstname path=request.firstname | spath input=req_xml output=lastname path=request.lastname | spath input=req_xml output=id path=request.id | spath input=req_json output=firstname path=firstname | spath input=req_json output=lastname path=lastname | spath input=req_json output=id path=id | spath input=resp_xml output=detail_type path=error.detail.type | spath input=resp_xml output=detail_annotation path=error.detail.annotation | spath input=resp_json output=detail_type path=detail{}.type | spath input=resp_json output=detail_annotation path=detail{}.annotation | fields - *xml *json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The juicy bits are in the bottom nine or so lines.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2013 20:56:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42785#M10044</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-25T20:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting field from JSON and XML response</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42786#M10045</link>
      <description>&lt;P&gt;Thanks martin. The two logs above are actually 2 different events.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2013 00:00:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42786#M10045</guid>
      <dc:creator>dbautist</dc:creator>
      <dc:date>2013-02-26T00:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting field from JSON and XML response</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42787#M10046</link>
      <description>&lt;P&gt;I am aware of that - if you run the above query you'll see two events treated equally.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2013 07:01:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-field-from-JSON-and-XML-response/m-p/42787#M10046</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-26T07:01:15Z</dc:date>
    </item>
  </channel>
</rss>

