AshKeys

Confessions and Confusions of Ashok M A. Personal and Professional Blog.

Ashok Mannolu Arunachalam, JavaMosquittoMQTTJSONFix
Back

Mosquitto: was expecting double-quote to start field name

I recently encountered the following exception in my Spring Boot Rest application when I published a MQTT message for a topic.

I was testing the MQTT subscribers whether they get the published message or not.

org.codehaus.jackson.JsonParseException: Unexpected character ('s' (code 110)): was expecting double-quote to start field name

I published the below message:

shell
$ mosquitto_pub -t "/v1/ashkeys/site" -m "{site:"ashokma.com"}"

After some googling I found out that field names should be double-quoted.

I know it was obvious from the exception itself. Dumb me >_<

Now the following works just fine with the subscribers.

shell
$ mosquitto_pub -t "/v1/ashkeys/site" -m "{"site":"ashokma.com"}"

The MQTT subscribers in turn use the jackson parser which adheres JSON specification. JSON specification demands that field names in a JSON should be double-quoted.