Mqtt json parser

Hi everyonE
Im trying to parse mqqt payload from mqtt consumer to influxdb

{
PointName":“ac:Data/ATA/ATA_3/Capteurs/Hygro_Ambiante/PresentValue”,
“Valeur”:“52.1 PERCENT”,
“time”:“2020-05-09T13:35:08.026Z”
}

Did you get the solution?

For [v2.0.3], there is an api json.parse can parse json value.
But the _value should not have any special char code, just like \n, \t

import "experimental/json"

data
  |> map(fn: (r) => {
      jsonData = json.parse(data: bytes(v: r._value))

      return {
        _time: r._time,
        _field: r._field,
        a: jsonData.a,
        b: jsonData.b,
        c: jsonData.c,
      }
    })

Hello @kaisawind,

Welcome. I’m having trouble understanding your question. Or is it just a suggestion? If you have a question about that flux function, can you please supply some input data and your expected output data?

Thank you

Yes, it’s just a suggestion for parse json value.Maybe it can help others.

1 Like