<?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 Problem with parsing JSON from MQTT input in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Problem-with-parsing-JSON-from-MQTT-input/m-p/474795#M58351</link>
    <description>&lt;P&gt;I'd like to parse and index JSON data which come from MQTT.&lt;BR /&gt;
Lets say that (for now) it is simple time-value JSON:&lt;BR /&gt;
&lt;CODE&gt;{"time": "2020-04-07 16:30:00", "value": 40}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I've installed MQTT Modular Input, cloned default "_json" Source Type and named it "simple_json". Only thing I've changed was setting "Timestamp fields" to "time".&lt;/P&gt;

&lt;P&gt;I've added new MQTT Data Input:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Stanza Name: simple_json_mqtt&lt;/LI&gt;
&lt;LI&gt;Activation Key: valid key for trial version&lt;/LI&gt;
&lt;LI&gt;Data Output: STDOUT&lt;/LI&gt;
&lt;LI&gt;Topic Name: simplejson/1&lt;/LI&gt;
&lt;LI&gt;Broker Host: mqtt-broker (name of docker image with Mosquitto broker)&lt;/LI&gt;
&lt;LI&gt;Broker Port: 1883 (no security)&lt;/LI&gt;
&lt;LI&gt;Client ID: simplejsonmqtt&lt;/LI&gt;
&lt;LI&gt;QOS: 1&lt;/LI&gt;
&lt;LI&gt;Set sourcetype: From list&lt;/LI&gt;
&lt;LI&gt;Select source type from list: simple_json
(other fields left blank/default)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Now I'm sending single message (using MQTTBox):&lt;BR /&gt;
&lt;CODE&gt;{"time": "2020-04-07 16:30:00", "value": 40}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In splunk/data/var/log/splunk/splunkd.log I can see:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;04-07-2020 15:17:07.800 +0000 ERROR JsonLineBreaker - JSON StreamId:14709566222301315061 had parsing error:Unexpected character while looking for value: 'T' - data_source="mqtt://simple_json_mqtt", data_host="splunk", data_sourcetype="simple_json"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Search for sourcetype="simple_json" returns no results&lt;/P&gt;

&lt;P&gt;Lets try with empty lines before and after json:&lt;BR /&gt;
`&lt;BR /&gt;
 {"time": "2020-04-07 16:31:00", "value": 41}&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
In log:&lt;BR /&gt;
&lt;/CODE&gt;04-07-2020 15:19:34.655 +0000 ERROR JsonLineBreaker - JSON StreamId:14709566222301315061 had parsing error:Unexpected character while looking for value: 'T' - data_source="mqtt://simple_json_mqtt", data_host="splunk", data_sourcetype="simple_json"`&lt;/P&gt;

&lt;P&gt;Search for sourcetype="simple_json" returns:&lt;BR /&gt;
&lt;CODE&gt;{"time": "2020-04-07 16:31:00", "value": 41}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Ok, now lets try to send two "events" in one MQTT message (with empty line at the end):&lt;BR /&gt;
`{"time": "2020-04-07 16:32:00", "value": 42}&lt;BR /&gt;
{"time": "2020-04-07 16:33:00", "value": 43}&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
In log: &lt;BR /&gt;
&lt;/CODE&gt;04-07-2020 15:23:21.951 +0000 ERROR JsonLineBreaker - JSON StreamId:14709566222301315061 had parsing error:Unexpected character while looking for value: 'T' - data_source="mqtt://simple_json_mqtt", data_host="splunk", data_sourcetype="simple_json"`&lt;/P&gt;

&lt;P&gt;Search for sourcetype="simple_json" returns:&lt;BR /&gt;
&lt;CODE&gt;{"time": "2020-04-07 16:33:00", "value": 43}&lt;BR /&gt;
{"time": "2020-04-07 16:31:00", "value": 41}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So i guess there is some kind of problem with LINE_BREAKER setting in source type (by default set to: ([\r\n]+))&lt;/P&gt;

&lt;P&gt;In the real world scenario, I won't be able to control format of JSON messages put in MQTT topic:&lt;BR /&gt;
- order of fields&lt;BR /&gt;
- existence of fields (lets say that "time" and "value" will be always there but also other objects/arrays/simple fields may appear)&lt;BR /&gt;
- LINE_BREAKER&lt;/P&gt;

&lt;P&gt;It is even possible to configure input type / source type to be able to parse "anything"?&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 04:59:29 GMT</pubDate>
    <dc:creator>pawelzak</dc:creator>
    <dc:date>2020-09-30T04:59:29Z</dc:date>
    <item>
      <title>Problem with parsing JSON from MQTT input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Problem-with-parsing-JSON-from-MQTT-input/m-p/474795#M58351</link>
      <description>&lt;P&gt;I'd like to parse and index JSON data which come from MQTT.&lt;BR /&gt;
Lets say that (for now) it is simple time-value JSON:&lt;BR /&gt;
&lt;CODE&gt;{"time": "2020-04-07 16:30:00", "value": 40}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I've installed MQTT Modular Input, cloned default "_json" Source Type and named it "simple_json". Only thing I've changed was setting "Timestamp fields" to "time".&lt;/P&gt;

&lt;P&gt;I've added new MQTT Data Input:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Stanza Name: simple_json_mqtt&lt;/LI&gt;
&lt;LI&gt;Activation Key: valid key for trial version&lt;/LI&gt;
&lt;LI&gt;Data Output: STDOUT&lt;/LI&gt;
&lt;LI&gt;Topic Name: simplejson/1&lt;/LI&gt;
&lt;LI&gt;Broker Host: mqtt-broker (name of docker image with Mosquitto broker)&lt;/LI&gt;
&lt;LI&gt;Broker Port: 1883 (no security)&lt;/LI&gt;
&lt;LI&gt;Client ID: simplejsonmqtt&lt;/LI&gt;
&lt;LI&gt;QOS: 1&lt;/LI&gt;
&lt;LI&gt;Set sourcetype: From list&lt;/LI&gt;
&lt;LI&gt;Select source type from list: simple_json
(other fields left blank/default)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Now I'm sending single message (using MQTTBox):&lt;BR /&gt;
&lt;CODE&gt;{"time": "2020-04-07 16:30:00", "value": 40}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;In splunk/data/var/log/splunk/splunkd.log I can see:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;04-07-2020 15:17:07.800 +0000 ERROR JsonLineBreaker - JSON StreamId:14709566222301315061 had parsing error:Unexpected character while looking for value: 'T' - data_source="mqtt://simple_json_mqtt", data_host="splunk", data_sourcetype="simple_json"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Search for sourcetype="simple_json" returns no results&lt;/P&gt;

&lt;P&gt;Lets try with empty lines before and after json:&lt;BR /&gt;
`&lt;BR /&gt;
 {"time": "2020-04-07 16:31:00", "value": 41}&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
In log:&lt;BR /&gt;
&lt;/CODE&gt;04-07-2020 15:19:34.655 +0000 ERROR JsonLineBreaker - JSON StreamId:14709566222301315061 had parsing error:Unexpected character while looking for value: 'T' - data_source="mqtt://simple_json_mqtt", data_host="splunk", data_sourcetype="simple_json"`&lt;/P&gt;

&lt;P&gt;Search for sourcetype="simple_json" returns:&lt;BR /&gt;
&lt;CODE&gt;{"time": "2020-04-07 16:31:00", "value": 41}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Ok, now lets try to send two "events" in one MQTT message (with empty line at the end):&lt;BR /&gt;
`{"time": "2020-04-07 16:32:00", "value": 42}&lt;BR /&gt;
{"time": "2020-04-07 16:33:00", "value": 43}&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
In log: &lt;BR /&gt;
&lt;/CODE&gt;04-07-2020 15:23:21.951 +0000 ERROR JsonLineBreaker - JSON StreamId:14709566222301315061 had parsing error:Unexpected character while looking for value: 'T' - data_source="mqtt://simple_json_mqtt", data_host="splunk", data_sourcetype="simple_json"`&lt;/P&gt;

&lt;P&gt;Search for sourcetype="simple_json" returns:&lt;BR /&gt;
&lt;CODE&gt;{"time": "2020-04-07 16:33:00", "value": 43}&lt;BR /&gt;
{"time": "2020-04-07 16:31:00", "value": 41}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So i guess there is some kind of problem with LINE_BREAKER setting in source type (by default set to: ([\r\n]+))&lt;/P&gt;

&lt;P&gt;In the real world scenario, I won't be able to control format of JSON messages put in MQTT topic:&lt;BR /&gt;
- order of fields&lt;BR /&gt;
- existence of fields (lets say that "time" and "value" will be always there but also other objects/arrays/simple fields may appear)&lt;BR /&gt;
- LINE_BREAKER&lt;/P&gt;

&lt;P&gt;It is even possible to configure input type / source type to be able to parse "anything"?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:59:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Problem-with-parsing-JSON-from-MQTT-input/m-p/474795#M58351</guid>
      <dc:creator>pawelzak</dc:creator>
      <dc:date>2020-09-30T04:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with parsing JSON from MQTT input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Problem-with-parsing-JSON-from-MQTT-input/m-p/474796#M58352</link>
      <description>&lt;P&gt;&lt;CODE&gt;{"time": "2020-04-07 16:33:00", "value": 43} {"time": "2020-04-07 16:31:00", "value": 41}&lt;/CODE&gt;&lt;BR /&gt;
It may be extra character, not &lt;CODE&gt;[\r\n]+&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;LINE_BREAKER = }(.)&lt;/CODE&gt;&lt;BR /&gt;
How about this?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 20:05:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Problem-with-parsing-JSON-from-MQTT-input/m-p/474796#M58352</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-10T20:05:02Z</dc:date>
    </item>
  </channel>
</rss>

