<?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: Differentiate between two fields with the same name in two different jsons in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403527#M116762</link>
    <description>&lt;P&gt;@seomaniv add the following eval before &lt;CODE&gt;spath&lt;/CODE&gt; commands.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval requestJson="{\"request\":".requestJson."\}", responseJson="{\"response\":".responseJson."\}"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search example based on the sample data provided:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="This event received the following request {\"clientId\":123,\"name\":null,\"ssn\":null} and sent the following response {\"clientId\":123,\"name\":\"John\",\"ssn\":\"Doe\"}"
| rex "This event received the following request (?&amp;lt;requestJson&amp;gt;.*) and sent the following response (?&amp;lt;responseJson&amp;gt;.*)"
| eval requestJson="{\"request\":".requestJson."\}", responseJson="{\"response\":".responseJson."\}"
| spath input=requestJson
| spath input=responseJson
| fields - _raw requestJson responseJson
| fields request* response*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm!&lt;/P&gt;</description>
    <pubDate>Tue, 09 Apr 2019 18:43:10 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-04-09T18:43:10Z</dc:date>
    <item>
      <title>Differentiate between two fields with the same name in two different jsons</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403526#M116761</link>
      <description>&lt;P&gt;So I have a single log event that captures the request and the response JSONs. As a user I'd like to be able to write a query that will capture the fields from the JSONs, but the field names are the same in the request and the response, so when I search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" sourcetype="mySourceType" "Keywords to search for only request and response events" | 
rex field=_raw "This event received the following request (?&amp;lt;requestJson&amp;gt;.*) and sent the following response (?&amp;lt;responseJson&amp;gt;.*)" | 
spath input=requestJson | 
spath input=responseJson
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I get the results of this search, I get one field with two values (request and response values):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"clientId":[123, 123] &amp;lt;-----searched by
"name":[null, "Joe Schmoe"]
"ssn":[null, "123-45-6789"]

.....etc.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I'd really like to be able to do is get a response more like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"request.clientId":123
 "request.name":null
 "request.ssn":null

"response.clientId":123
 "response.name":"Joe Schmoe"
 "response.ssn":"123-45-6789"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried renaming the fields in "requestJson" after using spath:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;spath input=requestJson | rename * as request.*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but that doesn't seem to work unless I use at least one letter before the wildcard (*), such as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;spath input=requestJson | rename a* as request.*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I rename these fields generated dynamically by spath-ing my JSONs? Or, alternative I may be missing: how can I differentiate between the request and response values even though they have the same field name?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:42:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403526#M116761</guid>
      <dc:creator>seomaniv</dc:creator>
      <dc:date>2019-04-09T17:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Differentiate between two fields with the same name in two different jsons</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403527#M116762</link>
      <description>&lt;P&gt;@seomaniv add the following eval before &lt;CODE&gt;spath&lt;/CODE&gt; commands.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval requestJson="{\"request\":".requestJson."\}", responseJson="{\"response\":".responseJson."\}"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search example based on the sample data provided:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="This event received the following request {\"clientId\":123,\"name\":null,\"ssn\":null} and sent the following response {\"clientId\":123,\"name\":\"John\",\"ssn\":\"Doe\"}"
| rex "This event received the following request (?&amp;lt;requestJson&amp;gt;.*) and sent the following response (?&amp;lt;responseJson&amp;gt;.*)"
| eval requestJson="{\"request\":".requestJson."\}", responseJson="{\"response\":".responseJson."\}"
| spath input=requestJson
| spath input=responseJson
| fields - _raw requestJson responseJson
| fields request* response*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 18:43:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403527#M116762</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-04-09T18:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Differentiate between two fields with the same name in two different jsons</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403528#M116763</link>
      <description>&lt;P&gt;Actually I ended up figuring it out, too. What I did was concatenate both fields into a single field, then ran spath on that field and it did the work itself. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval toSpath="{\"request\":".requestJson.",\"response\":".responseJson | 
spath input=toSpath
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Same thing you did, basically. Thanks niketnilay!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 18:49:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403528#M116763</guid>
      <dc:creator>seomaniv</dc:creator>
      <dc:date>2019-04-09T18:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Differentiate between two fields with the same name in two different jsons</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403529#M116764</link>
      <description>&lt;P&gt;@seomaniv ,Anytime! Glad you figured it out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 19:09:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Differentiate-between-two-fields-with-the-same-name-in-two/m-p/403529#M116764</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-04-09T19:09:22Z</dc:date>
    </item>
  </channel>
</rss>

