<?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: Getting json argument value of an attribute depending on value of another attribute. in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471842#M81078</link>
    <description>&lt;P&gt;@dipudan I know you already have an answer that works for you. Here is a different approach where, &lt;CODE&gt;errorstacktrace&lt;/CODE&gt; node is inserted to your raw data with dummy value ( &lt;CODE&gt;NA&lt;/CODE&gt; in this case) for the SPL to perform 1 to 1 mapping for each fields in the test case being executed. The following should print out the complete report from where you can apply filter on &lt;CODE&gt;errorstacktrace != NA&lt;/CODE&gt; to get specific rows.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourCurrentSearch&amp;gt;
| eval _raw=replace(_raw,"(\"skipped\":[^\,]+,\s+)(\"failedsince\")","\1\"errorstacktrace\":\"NA\",\2") 
| spath 
| fields - _* 
| rename "testsuite.testcase{}.testname" as testname, "testsuite.testcase{}.errorstacktrace" as errorstacktrace, "testsuite.testcase{}.duration" as duration, "testsuite.testcase{}.failedsince" as failedsince 
| fields build_number job_result testsuite.duration testsuite.failures testsuite.passes testsuite.total testsuite.duration testsuite.skips testname errorstacktrace duration failedsince
| eval data=mvzip(mvzip(mvzip(testname,errorstacktrace),duration),failedsince) 
| mvexpand data
| makemv data delim=","
| eval testname=mvindex(data,0),errorstacktrace=mvindex(data,1),duration=mvindex(data,2),failedsince=mvindex(data,3) 
| fields - data 
| eval errorstacktrace=replace(errorstacktrace,"\s+","")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 22 Dec 2019 17:36:14 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-12-22T17:36:14Z</dc:date>
    <item>
      <title>Getting json argument value of an attribute depending on value of another attribute.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471837#M81073</link>
      <description>&lt;P&gt;Hi Everyone,&lt;BR /&gt;
I am new with splunk queries. I am trying to retrieve a table with the data's build_number,errorstacktrace, and the testname for the nodes which is having "errorstacktrace" attribute in the below json. I tried the query &lt;/P&gt;

&lt;P&gt;index="*" job_name="testcafe" "event_tag":"build_report" | table  build_number ,testsuite.failures,testsuite.testcase{}.errorstacktrace,testsuite.testcase{}.testname | where 'testsuite.testcase{}.errorstacktrace' not null&lt;/P&gt;

&lt;P&gt;but it is giving me all the testname in the json. I only wan't the "testname" which is having "errorstacktrace" attribute. Can anyone guide on how to proceed here ?&lt;/P&gt;

&lt;P&gt;{ &lt;BR /&gt;
   "event_tag":"build_report",&lt;BR /&gt;
   "metadata":{ &lt;/P&gt;

&lt;P&gt;},&lt;BR /&gt;
   "job_name":"TestCafe",&lt;BR /&gt;
   "testsuite":{ &lt;BR /&gt;
      "failures":2,&lt;BR /&gt;
      "passes":7,&lt;BR /&gt;
      "skips":0,&lt;BR /&gt;
      "total":9,&lt;BR /&gt;
      "duration":115.06799,&lt;BR /&gt;
      "tests":9,&lt;BR /&gt;
      "time":115.06799,&lt;BR /&gt;
      "errors":0,&lt;BR /&gt;
      "testcase":[ &lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":1.664,&lt;BR /&gt;
            "classname":"API",&lt;BR /&gt;
            "testname":"should return last 10 posts",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "failedsince":0,&lt;BR /&gt;
            "uniquename":"API.should return last 10 posts",&lt;BR /&gt;
            "status":"PASSED"&lt;BR /&gt;
         },&lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":11.816,&lt;BR /&gt;
            "classname":"Login Test",&lt;BR /&gt;
            "testname":"should log into QualityShepherd.com",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "failedsince":0,&lt;BR /&gt;
            "uniquename":"Login Test.should log into QualityShepherd.com",&lt;BR /&gt;
            "status":"PASSED"&lt;BR /&gt;
         },&lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":2.424,&lt;BR /&gt;
            "classname":"Login Test",&lt;BR /&gt;
            "testname":"invalid credentials should display error",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "failedsince":0,&lt;BR /&gt;
            "uniquename":"Login Test.invalid credentials should display error",&lt;BR /&gt;
            "status":"PASSED"&lt;BR /&gt;
         },&lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":5.357,&lt;BR /&gt;
            "classname":"Quality Shepherd blog",&lt;BR /&gt;
            "testname":"should display 5 posts per page",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "errorstacktrace":"\n    \n      1) AssertionError: expected 5 to deeply equal",&lt;BR /&gt;
            "failedsince":29,&lt;BR /&gt;
            "uniquename":"Quality Shepherd blog.should display 5 posts per page",&lt;BR /&gt;
            "status":"FAILURE"&lt;BR /&gt;
         },&lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":9.18,&lt;BR /&gt;
            "classname":"Quality Shepherd blog",&lt;BR /&gt;
            "testname":"should return search results",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "failedsince":0,&lt;BR /&gt;
            "uniquename":"Quality Shepherd blog.should return search results",&lt;BR /&gt;
            "status":"PASSED"&lt;BR /&gt;
         },&lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":6.499,&lt;BR /&gt;
            "classname":"Quality Shepherd blog",&lt;BR /&gt;
            "testname":"unfound search term should return no results",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "failedsince":0,&lt;BR /&gt;
            "uniquename":"Quality Shepherd blog.unfound search term should return no results",&lt;BR /&gt;
            "status":"PASSED"&lt;BR /&gt;
         },&lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":9.719,&lt;BR /&gt;
            "classname":"Quality Shepherd blog",&lt;BR /&gt;
            "testname":"should open social media link in new window",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "failedsince":0,&lt;BR /&gt;
            "uniquename":"Quality Shepherd blog.should open social media link in new window",&lt;BR /&gt;
            "status":"PASSED"&lt;BR /&gt;
         },&lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":5.123,&lt;BR /&gt;
            "classname":"Quality Shepherd blog",&lt;BR /&gt;
            "testname":"sidebar should have a set width",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "failedsince":0,&lt;BR /&gt;
            "uniquename":"Quality Shepherd blog.sidebar should have a set width",&lt;BR /&gt;
            "status":"PASSED"&lt;BR /&gt;
         },&lt;BR /&gt;
         { &lt;BR /&gt;
            "duration":63.286,&lt;BR /&gt;
            "classname":"Quality Shepherd blog",&lt;BR /&gt;
            "testname":"should find an older post by paging",&lt;BR /&gt;
            "groupname":"TestCafe Tests_ Chrome 79.0.3945.88 _ Windows 10",&lt;BR /&gt;
            "skipped":false,&lt;BR /&gt;
            "errorstacktrace":"1) The specified selector does not match any element in the DOM tree.",&lt;BR /&gt;
            "failedsince":30,&lt;BR /&gt;
            "uniquename":"Quality Shepherd blog.should find an older post by paging",&lt;BR /&gt;
            "status":"FAILURE"&lt;BR /&gt;
         }&lt;BR /&gt;
      ]&lt;BR /&gt;
   },&lt;BR /&gt;
   "build_number":30,&lt;BR /&gt;
   "page_num":1,&lt;BR /&gt;
   "job_result":"FAILURE",&lt;BR /&gt;
   "user":"Dipu Krishnan",&lt;BR /&gt;
   "build_url":"job/TestCafe/30/"&lt;BR /&gt;
}&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:28:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471837#M81073</guid>
      <dc:creator>dipudan</dc:creator>
      <dc:date>2020-09-30T03:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Getting json argument value of an attribute depending on value of another attribute.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471838#M81074</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{
\"event_tag\":\"build_report\",
\"metadata\":{

},
\"job_name\":\"TestCafe\",
\"testsuite\":{
\"failures\":2,
\"passes\":7,
\"skips\":0,
\"total\":9,
\"duration\":115.06799,
\"tests\":9,
\"time\":115.06799,
\"errors\":0,
\"testcase\":[
{
\"duration\":1.664,
\"classname\":\"API\",
\"testname\":\"should return last 10 posts\",
\"groupname\":\"TestCafe Tests_ Chrome 79.0.3945.88 Windows 10\",
\"skipped\":false,
\"failedsince\":0,
\"uniquename\":\"API.should return last 10 posts\",
\"status\":\"PASSED\"
},
{
\"duration\":11.816,
\"classname\":\"Login Test\",
\"testname\":\"should log into QualityShepherd.com\",
\"groupname\":\"TestCafe Tests Chrome 79.0.3945.88 Windows 10\",
\"skipped\":false,
\"failedsince\":0,
\"uniquename\":\"Login Test.should log into QualityShepherd.com\",
\"status\":\"PASSED\"
},
{
\"duration\":2.424,
\"classname\":\"Login Test\",
\"testname\":\"invalid credentials should display error\",
\"groupname\":\"TestCafe Tests Chrome 79.0.3945.88 Windows 10\",
\"skipped\":false,
\"failedsince\":0,
\"uniquename\":\"Login Test.invalid credentials should display error\",
\"status\":\"PASSED\"
},
{
\"duration\":5.357,
\"classname\":\"Quality Shepherd blog\",
\"testname\":\"should display 5 posts per page\",
\"groupname\":\"TestCafe Tests Chrome 79.0.3945.88 Windows 10\",
\"skipped\":false,
\"errorstacktrace\":\"\n \n 1) AssertionError: expected 5 to deeply equal\",
\"failedsince\":29,
\"uniquename\":\"Quality Shepherd blog.should display 5 posts per page\",
\"status\":\"FAILURE\"
},
{
\"duration\":9.18,
\"classname\":\"Quality Shepherd blog\",
\"testname\":\"should return search results\",
\"groupname\":\"TestCafe Tests Chrome 79.0.3945.88 Windows 10\",
\"skipped\":false,
\"failedsince\":0,
\"uniquename\":\"Quality Shepherd blog.should return search results\",
\"status\":\"PASSED\"
},
{
\"duration\":6.499,
\"classname\":\"Quality Shepherd blog\",
\"testname\":\"unfound search term should return no results\",
\"groupname\":\"TestCafe Tests Chrome 79.0.3945.88 Windows 10\",
\"skipped\":false,
\"failedsince\":0,
\"uniquename\":\"Quality Shepherd blog.unfound search term should return no results\",
\"status\":\"PASSED\"
},
{
\"duration\":9.719,
\"classname\":\"Quality Shepherd blog\",
\"testname\":\"should open social media link in new window\",
\"groupname\":\"TestCafe Tests Chrome 79.0.3945.88 Windows 10\",
\"skipped\":false,
\"failedsince\":0,
\"uniquename\":\"Quality Shepherd blog.should open social media link in new window\",
\"status\":\"PASSED\"
},
{
\"duration\":5.123,
\"classname\":\"Quality Shepherd blog\",
\"testname\":\"sidebar should have a set width\",
\"groupname\":\"TestCafe Tests Chrome 79.0.3945.88 Windows 10\",
\"skipped\":false,
\"failedsince\":0,
\"uniquename\":\"Quality Shepherd blog.sidebar should have a set width\",
\"status\":\"PASSED\"
},
{
\"duration\":63.286,
\"classname\":\"Quality Shepherd blog\",
\"testname\":\"should find an older post by paging\",
\"groupname\":\"TestCafe Tests Chrome 79.0.3945.88 _ Windows 10\",
\"skipped\":false,
\"errorstacktrace\":\"1) The specified selector does not match any element in the DOM tree.\",
\"failedsince\":30,
\"uniquename\":\"Quality Shepherd blog.should find an older post by paging\",
\"status\":\"FAILURE\"
}
]
},
\"build_number\":30,
\"page_num\":1,
\"job_result\":\"FAILURE\",
\"user\":\"Dipu Krishnan\",
\"build_url\":\"job/TestCafe/30/\"
}"
| rename COMMENT as "This is sample you provide"
| rename COMMENT as "From here, the logic"
| eval build_number=spath(_raw,"build_number")
| eval failures=spath(_raw,"testsuite.failures")
| spath path=testsuite.testcase{} output=testcase
| fields - _*
| mvexpand testcase
| where mvfind(testcase,"errorstacktrace") = 0
| spath input=testcase
| table build_number ,failures,errorstacktrace,testname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hi, @dipudan &lt;BR /&gt;
How about this?&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2019 07:56:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471838#M81074</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-22T07:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Getting json argument value of an attribute depending on value of another attribute.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471839#M81075</link>
      <description>&lt;P&gt;@to4kawa&lt;BR /&gt;
It worked perfectly. Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2019 08:51:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471839#M81075</guid>
      <dc:creator>dipudan</dc:creator>
      <dc:date>2019-12-22T08:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Getting json argument value of an attribute depending on value of another attribute.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471840#M81076</link>
      <description>&lt;P&gt;your welcome&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2019 08:56:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471840#M81076</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-22T08:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Getting json argument value of an attribute depending on value of another attribute.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471841#M81077</link>
      <description>&lt;P&gt;Thanks @to4kawa, learnt a new way to use &lt;CODE&gt;spath with eval&lt;/CODE&gt; and &lt;CODE&gt;mvfind with where&lt;/CODE&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2019 17:32:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471841#M81077</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-12-22T17:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Getting json argument value of an attribute depending on value of another attribute.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471842#M81078</link>
      <description>&lt;P&gt;@dipudan I know you already have an answer that works for you. Here is a different approach where, &lt;CODE&gt;errorstacktrace&lt;/CODE&gt; node is inserted to your raw data with dummy value ( &lt;CODE&gt;NA&lt;/CODE&gt; in this case) for the SPL to perform 1 to 1 mapping for each fields in the test case being executed. The following should print out the complete report from where you can apply filter on &lt;CODE&gt;errorstacktrace != NA&lt;/CODE&gt; to get specific rows.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourCurrentSearch&amp;gt;
| eval _raw=replace(_raw,"(\"skipped\":[^\,]+,\s+)(\"failedsince\")","\1\"errorstacktrace\":\"NA\",\2") 
| spath 
| fields - _* 
| rename "testsuite.testcase{}.testname" as testname, "testsuite.testcase{}.errorstacktrace" as errorstacktrace, "testsuite.testcase{}.duration" as duration, "testsuite.testcase{}.failedsince" as failedsince 
| fields build_number job_result testsuite.duration testsuite.failures testsuite.passes testsuite.total testsuite.duration testsuite.skips testname errorstacktrace duration failedsince
| eval data=mvzip(mvzip(mvzip(testname,errorstacktrace),duration),failedsince) 
| mvexpand data
| makemv data delim=","
| eval testname=mvindex(data,0),errorstacktrace=mvindex(data,1),duration=mvindex(data,2),failedsince=mvindex(data,3) 
| fields - data 
| eval errorstacktrace=replace(errorstacktrace,"\s+","")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Dec 2019 17:36:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471842#M81078</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-12-22T17:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Getting json argument value of an attribute depending on value of another attribute.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471843#M81079</link>
      <description>&lt;P&gt;Hooray  XD　&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2019 19:39:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Getting-json-argument-value-of-an-attribute-depending-on-value/m-p/471843#M81079</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-22T19:39:43Z</dc:date>
    </item>
  </channel>
</rss>

