Json format / MQTT subscription / objectJSON

Hi everyone,
I publish here because i see there are more active discussion around MQTT .
I’m working with:
chirpstack-application-server version : 3.10.0
chirpstack-network-server version : 3.9.0
chirpstack-gateway-bridge version : 3.8.0

All on a rpi with raspbian buster…

The problem is when i subscribe to my application topic events i receive the “objectJSON” as a string format (double quoted and unescaped ) like if its stringify twice during the transport…

If i do this command on the gateway:
mosquitto_sub -t "application/3/#" -v

application/3/device/12345678910/rx {"applicationID":"3","applicationName":"sondehumtemp","deviceName":"node01","devEUI":"123456789=",

The induce problem is i cant do JSON.parse(myMQTTmessage).
error unexpected token at position...

I use this script for decode payload data, that you can found here: (i have just remove all the unit for a simpler integration…)

Just to add : i have integrate this “data events” into a postgres data base … all look very good , I could “query” without problems differents elements of the objectJSON.

i have ask on the RAK forum if they have the same problem … they answer that with the same script but an old version of chirpstack the result is different (in their case no problems).

Thanks for the help.

This might be an issue with the JSON parsing, I have checked www.jsonlint.com and the JSON payload is valid. Please note that objectJSON must be seen as a string, not an object. That string needs to be parsed separately.

Please see the definition of this message here: https://github.com/brocaar/chirpstack-api/blob/master/protobuf/as/integration/integration.proto#L81.

Thanks for your quick answer!
OK its like this … the ObjectJSON is receive as “string” !!
So i have to use a different way to extract it from the MQTT message… Why not if i have the control on the MQTT client. but that not the case for certain applications. doesn’t matter.
I will try to get the base64 data first and decode them in a second time with an other task.
Its certainly more efficient than to send decoded data …
Efficient but more complicated…

At the end again thanks for your quick answer!

When i have started to search why i get this “string object” i ask to RAK if its come from their decode payload script. and we have a conversation about it.
The discussion is here: https://forum.rakwireless.com/t/scripts-to-decode-rak-node-rak5205-rak7205-rak7200-rak7204-sensor-data-for-ttn-and-chirpstack/1732/12

They dont have the same result like me.
please have a look on the result of a mosquitto_sub with the RAK’s version:

application/2/device/3739343557376202/rx {“applicationID”:“2”,“applicationName”:“1”,“deviceName”:“3739343557376202”,“devEUI”:“3739343557376202”,“txInfo”:{“frequency”:487100000,“dr”:5},“adr”:true,“fCnt”:6,“fPort”:8,“data”:“CAIBogdoLAZzJW8CZwFHBAIR5QNxAxkAJf2n”,“object”:{“acceleration_x”:0.793,“acceleration_y”:0.037,“acceleration_z”:-0.601,“barometer”:958.3,“battery”:4.18,“gasResistance”:45.81,“humidity”:22,“temperature”:32.7}}

The decoded data named here object and not objectJSON is directly in Json format (keys + fields).

I’m very bad with javascript and Json so maybe i’m totally wrong about this but :

  • Is it possible to have an option to control this format? (into config file) ?
  • I have a mqtt client who wait for data into key + field format… so with the format “string” i cant do anything (i haven’t the possibility to apply a function or something like this). and i suppose i’m not the only one in this position.


It is already there :wink:

  # Integration configures the data integration.
  # This is the data integration which is available for all applications,
  # besides the extra integrations that can be added on a per-application
  # basis.
  # Payload marshaler.
  # This defines how the MQTT payloads are encoded. Valid options are:
  # * protobuf:  Protobuf encoding
  # * json:      JSON encoding (easier for debugging, but less compact than 'protobuf')
  # * json_v3:   v3 JSON (will be removed in the next major release)


I recommend you to use the json or protobuf however as it is using the Protobuf message format as defined here: https://github.com/brocaar/chirpstack-api/blob/master/protobuf/as/integration/integration.proto

Ok some aspect are clearer. Thanks.
I understand too why Rak have not the same MQTT message with the same codec.
They use the Marsahler Json_v3. And as i use the marshaler JSON , difference come from here.

For me protobuff is (impossible) to integrate with my MQTT client. Json only is supported .
So i could use the Json_v3 Marshaler and it will working perfectly .
But first : it said that this encoding type will be deprecated. So i prefer starting my integration with JSON.

second, My base problem persist. i can’t get a JsonObject with “keys” and “fields” to integrate it easely on my MQTT client. As it’s appear as a String with the JSON marshaler.
Of course i understand that normaly the MQTT message could be parse and modified by the MQTT client. But with my MQTT it’s only Json Key and field. (In the field it wait for the final value )

So i will understand that this MQTT client is poor and i have to look for a Client with better configurations option. But at the end it’s not compatible.

I gonna see with the suplier of my MQTT client if they could do something for a better integration .