<?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: Why is the null value in a JSON event not being parsed properly as NULL? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204370#M40353</link>
    <description>&lt;P&gt;Thanks for this answer. I just ran into the same issue (in Splunk Enterprise 6.4).&lt;/P&gt;

&lt;P&gt;I am sending JSON-format logs to Splunk via the HTTP Event Collector (EC). Some field values are explicitly set to &lt;CODE&gt;null&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;some_performance_indicator_field: null
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One reason for setting a field value to &lt;CODE&gt;null&lt;/CODE&gt;, rather than omitting the field, is to indicate that the version of the performance monitoring system that generated this data &lt;EM&gt;does&lt;/EM&gt; report that performance indicator (from the underlying transaction processing system being monitored), but that, in this instance, there was no value to report. As opposed to a (typically earlier) system that &lt;EM&gt;does not&lt;/EM&gt; report that indicator, and so that field does not occur in its output. A &lt;CODE&gt;null&lt;/CODE&gt; value tells you something about the performance indicator, whereas, if the field is absent, the performance indicator might have had any value; it just wasn't reported.&lt;/P&gt;

&lt;P&gt;So (with apologies to readers who are well aware of this), there can be a significant semantic difference in JSON between a field being set to the explicit value &lt;CODE&gt;null&lt;/CODE&gt; and that field being omitted.&lt;/P&gt;

&lt;P&gt;It appears (and my own ad hoc testing confirms this answer) that Splunk interprets the JSON &lt;CODE&gt;null&lt;/CODE&gt; field value as the string value &lt;CODE&gt;"null"&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;That behavior is consistent with the following definition in the Splunk documentation topic "&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/Search/Aboutsearchlanguagesyntax"&gt;The search processing language syntax&lt;/A&gt;":&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Null field&lt;/STRONG&gt;&lt;BR /&gt;
A null field is not present on a particular result or event.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;(Although I would prefer it if the documentation explicitly covered the case of the JSON &lt;CODE&gt;null&lt;/CODE&gt; value being interpreted as the string value &lt;CODE&gt;"null"&lt;/CODE&gt;, and any  similar issues with other input data formats. Perhaps it does; just not in that topic.)&lt;/P&gt;

&lt;P&gt;I presume (I haven't tested this) that this means that, for the purposes of searching in Splunk, the following JSON KV pair:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myfield: null
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is identical to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myfield: "null"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Apr 2016 03:14:38 GMT</pubDate>
    <dc:creator>Graham_Hanningt</dc:creator>
    <dc:date>2016-04-20T03:14:38Z</dc:date>
    <item>
      <title>Why is the null value in a JSON event not being parsed properly as NULL?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204366#M40349</link>
      <description>&lt;P&gt;I have the following data coming into Splunk in JSON format and extracted at index-time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ 
    administrativeState:  Unlocked 
    apGroupId:  7954abec-de25-4758-bb5e-0d87be2f0254 
    approvedTime:  1435500193785 
    clientCount:  0 
    configState:  newConfig 
    connectionState:  Disconnect 
    countryCode:  XX 
    cpId:  15e2811e-a24f-4570-bd58-8f18c7e6ed91 
    description: 
    dpId: 
    externalIp:  xxx.xx.xx.xx
    externalPort:  55540 
    ip:  xxx.xx.xx.xx
    ipType:  Static 
    ipv6: 
    ipv6Type:  null 
    isCriticalAP:  false 
    lastSeenTime:  1454078438291 
    latitude:  null 
    location:  XXXXXXXXX 
    longitude:  null 
    mac:  F0:B0:52:3B:F2:10 
    meshHop:  0 
    meshRole:  null 
    model:  T300 
    name:  XXXXXXXXX
    provisionMethod:  Discovered 
    provisionStage:  null 
    registrationState:  Approved 
    serial:  491484101277 
    uptime:  81630 
    version:  3.1.1.0.349 
    wifi24Channel:  2 
    wifi50Channel:  104 
    zoneId:  d41a3397-b859-42cd-9332-e308a48069b2 
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note: The latitude and logitude fields in this case are &lt;CODE&gt;null&lt;/CODE&gt; and Splunk's syntax highlighter shows it like null or boolean would be in any editor.&lt;/P&gt;

&lt;P&gt;I can search for &lt;CODE&gt;longitude=null&lt;/CODE&gt; no problems, however, when it comes to enriching the event with other data from a lookup and trying to coalesce the field with another like so: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval merged_latitude=coalesce(latitude,zone_lat,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then it appears to be assuming that &lt;CODE&gt;null&lt;/CODE&gt; is actually not null and using the &lt;CODE&gt;null&lt;/CODE&gt; value rather than attempting to look at the next field or even the fail safe &lt;CODE&gt;0&lt;/CODE&gt; value.&lt;/P&gt;

&lt;P&gt;In order to get the &lt;CODE&gt;null&lt;/CODE&gt; to be correctly seen as &lt;CODE&gt;NULL&lt;/CODE&gt; I have to insert the following into my search: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval latitude=if(latitude="null",FALSE,latitude)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This seems perhaps the "wrong" way to fix the problem, is there not a better approach to this?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 08:55:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204366#M40349</guid>
      <dc:creator>anthonysomerset</dc:creator>
      <dc:date>2016-02-16T08:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the null value in a JSON event not being parsed properly as NULL?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204367#M40350</link>
      <description>&lt;P&gt;Splunk sees "null" as a valid string value, hence all the issues. (and actually there is no notation that can be used to denote null values other then value not present at all). So to fix this, either you can replace all null with blank (no value) in the raw data before indexing (works only for future data) OR handle the same in search time.&lt;/P&gt;

&lt;P&gt;For option 1, see these&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/210096/how-to-configure-sedcmd-in-propsconf.html"&gt;https://answers.splunk.com/answers/210096/how-to-configure-sedcmd-in-propsconf.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.6/Data/Anonymizedatausingconfigurationfiles"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.6/Data/Anonymizedatausingconfigurationfiles&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For option 2, you already have one option listed. Others options could be like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | replace "null" with "" in field1, field2, field3

your base search | rex mode=sed "s/null//g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Feb 2016 22:39:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204367#M40350</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-02-16T22:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the null value in a JSON event not being parsed properly as NULL?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204368#M40351</link>
      <description>&lt;P&gt;Thanks - at least your suggestions are much more efficient than mine&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 06:14:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204368#M40351</guid>
      <dc:creator>anthonysomerset</dc:creator>
      <dc:date>2016-02-17T06:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the null value in a JSON event not being parsed properly as NULL?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204369#M40352</link>
      <description>&lt;P&gt;So it turns out that the first command the value is still treated as non NULL &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; and the rex command doesn't even appear to be doing anything at all &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 07:44:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204369#M40352</guid>
      <dc:creator>anthonysomerset</dc:creator>
      <dc:date>2016-02-17T07:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the null value in a JSON event not being parsed properly as NULL?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204370#M40353</link>
      <description>&lt;P&gt;Thanks for this answer. I just ran into the same issue (in Splunk Enterprise 6.4).&lt;/P&gt;

&lt;P&gt;I am sending JSON-format logs to Splunk via the HTTP Event Collector (EC). Some field values are explicitly set to &lt;CODE&gt;null&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;some_performance_indicator_field: null
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One reason for setting a field value to &lt;CODE&gt;null&lt;/CODE&gt;, rather than omitting the field, is to indicate that the version of the performance monitoring system that generated this data &lt;EM&gt;does&lt;/EM&gt; report that performance indicator (from the underlying transaction processing system being monitored), but that, in this instance, there was no value to report. As opposed to a (typically earlier) system that &lt;EM&gt;does not&lt;/EM&gt; report that indicator, and so that field does not occur in its output. A &lt;CODE&gt;null&lt;/CODE&gt; value tells you something about the performance indicator, whereas, if the field is absent, the performance indicator might have had any value; it just wasn't reported.&lt;/P&gt;

&lt;P&gt;So (with apologies to readers who are well aware of this), there can be a significant semantic difference in JSON between a field being set to the explicit value &lt;CODE&gt;null&lt;/CODE&gt; and that field being omitted.&lt;/P&gt;

&lt;P&gt;It appears (and my own ad hoc testing confirms this answer) that Splunk interprets the JSON &lt;CODE&gt;null&lt;/CODE&gt; field value as the string value &lt;CODE&gt;"null"&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;That behavior is consistent with the following definition in the Splunk documentation topic "&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/Search/Aboutsearchlanguagesyntax"&gt;The search processing language syntax&lt;/A&gt;":&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Null field&lt;/STRONG&gt;&lt;BR /&gt;
A null field is not present on a particular result or event.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;(Although I would prefer it if the documentation explicitly covered the case of the JSON &lt;CODE&gt;null&lt;/CODE&gt; value being interpreted as the string value &lt;CODE&gt;"null"&lt;/CODE&gt;, and any  similar issues with other input data formats. Perhaps it does; just not in that topic.)&lt;/P&gt;

&lt;P&gt;I presume (I haven't tested this) that this means that, for the purposes of searching in Splunk, the following JSON KV pair:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myfield: null
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is identical to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myfield: "null"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Apr 2016 03:14:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204370#M40353</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-20T03:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the null value in a JSON event not being parsed properly as NULL?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204371#M40354</link>
      <description>&lt;P&gt;This is still an issue for me in Splunk 7.3.0.&lt;/P&gt;

&lt;P&gt;Given the following input JSON Lines:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"code":"test_null_value","time":"2019-11-07T08:00:00+08:00","test":null}
{"code":"test_null_value","time":"2019-11-07T08:00:01+08:00","test":"null"}
{"code":"test_null_value","time":"2019-11-07T08:00:02+08:00","test":"present"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(For the purposes of this comment, you can ignore the &lt;CODE&gt;code&lt;/CODE&gt; and &lt;CODE&gt;time&lt;/CODE&gt; fields.)&lt;/P&gt;

&lt;P&gt;the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="test_null_value" test="null"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;returns two results: the event with &lt;CODE&gt;"null"&lt;/CODE&gt; and the event with &lt;CODE&gt;null&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Curiously, Splunk Web syntax-highlights the &lt;CODE&gt;null&lt;/CODE&gt; in &lt;CODE&gt;"test":null&lt;/CODE&gt; in orange, whereas the string value &lt;CODE&gt;null&lt;/CODE&gt; in &lt;CODE&gt;"test":"null"&lt;/CODE&gt; is green.&lt;/P&gt;

&lt;P&gt;The following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="test_null_value" | where isnull(test)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;returns no results, as expected: the (JavaScript) value &lt;CODE&gt;null&lt;/CODE&gt; does not correspond to Splunk's "not present" concept of NULL.&lt;/P&gt;

&lt;P&gt;I don't know of any way in a Splunk search to distinguish between the string value &lt;CODE&gt;"null"&lt;/CODE&gt; and the value &lt;CODE&gt;null&lt;/CODE&gt;. Splunk seems to treat them as identical string values. It seems that orange syntax highlighting in the Search app is just for show; skin deep.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 05:54:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/204371#M40354</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2019-11-07T05:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the null value in a JSON event not being parsed properly as NULL?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/508466#M86507</link>
      <description>&lt;P&gt;You can work around the "null" vs. null issue in some cases. You can use spath to get a bit more specific with nested JSON, but it isn't as simple as simple search criteria.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;index=_internal
| head 1
| fields _time, _raw
| eval _raw = "{\"nullable_field\": null, \"nullable_list_0\": [ null ], \"nullable_list_1\": [ \"null\", null ] }"
| spath
| regex "\"nullable_field\"\s*:\s*null\b" `comment("single values are easier to identify than lists; could be converted to a macro")`
| eval includes_null_as_string = if(searchmatch("\"null\""), "true", "false") `comment("events with string that is not null")`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 11:24:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-is-the-null-value-in-a-JSON-event-not-being-parsed-properly/m-p/508466#M86507</guid>
      <dc:creator>malvidin</dc:creator>
      <dc:date>2020-07-10T11:24:56Z</dc:date>
    </item>
  </channel>
</rss>

