<?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: In a dashboard query, how do you use a JSON field in an if statement? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446688#M77697</link>
    <description>&lt;P&gt;@ShagVT ,&lt;/P&gt;

&lt;P&gt;Add ' to the fieldname to make it as literal and then do the comparison.&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=newformat | eval blocked =if ('a.b.fieldname'=="BLOCKED", 1,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or &lt;BR /&gt;
Rename the field and compare&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=newformat|rename a.b.fieldname as fieldname |eval blocked =if (fieldname =="BLOCKED", 1,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Dec 2018 02:40:40 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2018-12-14T02:40:40Z</dc:date>
    <item>
      <title>In a dashboard query, how do you use a JSON field in an if statement?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446686#M77695</link>
      <description>&lt;P&gt;I have some data which is changing from a delimited format to JSON.  In a dashboard, I have a query that for the old format would do this:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;sourcetype=oldformat | eval blocked = if(fieldname=="BLOCKED",1,0)&lt;/STRONG&gt;&lt;BR /&gt;
However, trying this against the JSON it doesn't work right.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;sourcetype=newformat | eval blocked =if (a.b.fieldname=="BLOCKED", 1,0)&lt;/STRONG&gt;&lt;BR /&gt;
But this doesn't seem to work ... all records evaluate to 0.  I test this out, I ran the following, which was just bizarre:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;sourcetype=newformat a.b.fieldname="BLOCKED" | eval blocked =if (a.b.fieldname=="BLOCKED", 1,0) | chart count by a.b.fieldname, blocked&lt;/STRONG&gt;&lt;BR /&gt;
The result table looked like this:&lt;BR /&gt;
&lt;PRE&gt;&lt;BR /&gt;
a.b.fieldname        0&lt;BR /&gt;
BLOCKED              45&lt;BR /&gt;
&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;So it was able to search by the field name (it found only the correct records out of millions) and it shows the correct value (BLOCKED) ... but the if statement that works fine when not looking at JSON seems to be broken with the JSON.&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 21:26:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446686#M77695</guid>
      <dc:creator>ShagVT</dc:creator>
      <dc:date>2018-12-13T21:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: In a dashboard query, how do you use a JSON field in an if statement?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446687#M77696</link>
      <description>&lt;P&gt;did you see a.b.fieldname as a interesting field in your JSON data..??&lt;BR /&gt;
can you post a sample of you json data..??&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 02:38:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446687#M77696</guid>
      <dc:creator>prakash007</dc:creator>
      <dc:date>2018-12-14T02:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: In a dashboard query, how do you use a JSON field in an if statement?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446688#M77697</link>
      <description>&lt;P&gt;@ShagVT ,&lt;/P&gt;

&lt;P&gt;Add ' to the fieldname to make it as literal and then do the comparison.&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=newformat | eval blocked =if ('a.b.fieldname'=="BLOCKED", 1,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or &lt;BR /&gt;
Rename the field and compare&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=newformat|rename a.b.fieldname as fieldname |eval blocked =if (fieldname =="BLOCKED", 1,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Dec 2018 02:40:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446688#M77697</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-12-14T02:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: In a dashboard query, how do you use a JSON field in an if statement?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446689#M77698</link>
      <description>&lt;P&gt;Both of these ideas were successful.  &lt;STRONG&gt;THANK YOU!&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;So is this basically a bug in Splunk's evaluation of conditional functions?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 13:53:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/In-a-dashboard-query-how-do-you-use-a-JSON-field-in-an-if/m-p/446689#M77698</guid>
      <dc:creator>ShagVT</dc:creator>
      <dc:date>2018-12-14T13:53:41Z</dc:date>
    </item>
  </channel>
</rss>

