Documentation

JSON parsing examples

Use the following examples to help you set up JSON parsing rules using JSON Path for native subscriptions. All JSON paths start with a $.

Example MQTT message in “flat” JSON format

{
"device_type":"temperature_sensor",
"device_id":2036,
"model_id":"KN24683",
"temperature":25.0,
"time":1653998899010000000,
"error_state":"in_error"
}

With “flat” JSON, all values are at the root level ($) and are referenced with dot notation.

InfluxDB ElementJSON PathData TypeParsed Result
Measurement$.device_typeString“temperature_sensor”
Timestamp$.timeTimestamp1653998899010000000
Tag$.device_idInteger2036
Field 1$.temperatureFloat25.0
Field 2$.error_stateString“in_error”

Example MQTT message with nested JSON objects

{
  "device_information": {
    "device_type":"temperature_sensor",
    "device_id":2036,
    "model_id":"KN24683"
  },
  "temperature":25.0,
  "time":165411795400000000,
  "error_state":"in_error"
}
InfluxDB ElementJSON PathData TypeParsed Result
Measurement$.device_information.device_typeString“temperature_sensor”
Timestamp$.timeTimestamp1653998899010000000
Tag$.device_information.device_idInteger2036
Field 1$.temperatureFloat25.0
Field 2$.error_stateString“in_error”

Example MQTT message with JSON arrays

Currently, there is limited support for working with key/value pairs that are held within a JSON array. Entire arrays cannot be loaded into a single field value, but if your messages have a fixed number of values in the array being passed, you can specify an array index number in your JSON path.

{
   "device_information":{
      "device_type":"temperature_sensor",
      "device_id":2309,
      "model_id":"KN24683"
   },
   "time":1653998899010000000,
   "temperature":25.0,
   "error_state":"in_error",
   "errors_encountered":[
      {
         "time_encountered":"2022:05:30:23:11",
         "error_number":403
      },
      {
         "time_encountered":"2022:06:01:12:15",
         "error_number":404
      }
   ]
}
InfluxDB ElementJSON PathData TypeParsed Result
Measurement$.device_information.device_typeString“temperature_sensor”
Timestamp$.timeTimestamp1653998899010000000
Tag$.device_information.device_idInteger2036
Field 1$.temperatureFloat25.0
Field 2$.error_stateString“in_error”
Field 3$.errors_encountered.[0].error_numberInteger403
Field 4$.errors_encountered.[1].error_numberInteger404

Was this page helpful?

Thank you for your feedback!


Select your region

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.