# Passing JSON from MQTT into InfluxDB

**URL:** https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563
**Category:** General
**Created:** [20 August 2019 20:13 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563 "2019-08-20T20:13:25Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Axiom](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Axiom](https://discourse.nodered.org/u/Axiom)
#### Post date: [20 August 2019 20:13 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563/1 "2019-08-20T20:13:25Z")

</div>

Hello everyone,

I am running into problems sending my JSON data into InfluxDB. My JSON is being pulled in via MQTT in this format:

```auto
[
    {
        "measurement": "sensor data"
    },
    {
        "tags": {
            "location": "eic",
            "sensor": "sentry pro"
        }
    },
    {
        "time": 1566329777.4187512
    },
    {
        "fields": {
            "Temperature_F_Reference": [
                72.05
            ],
            "Time_Reference": [
                213.0
            ],
            "Real_Ohms_Working_1K": [
                67.659
            ],
            "Real_Ohms_Working_300": [
                89.2325
            ],
            "Working_Probe": [
                "Working"
            ],
            "Frequency_Working_1K": [
                1000.0
            ],
            "Cap_Working_300": [
                13.5837
            ],
            "Frequency_Working_300": [
                300.0
            ],
            "Img_Reference_300": [
                43.909
            ],
            "Real_Ohms_Reference_1K": [
                56.466
            ],
            "Img_Working_1K": [
                17.5842
            ],
            "Real_Ohms_Reference_300": [
                81.5604
            ],
            "Frequency_Reference_1K": [
                1000.0
            ],
            "Img_Working_300": [
                39.0554
            ],
            "Reference_Probe": [
                "Reference"
            ],
            "Cap_Working_1K": [
                9.051
            ],
            "Img_Reference_1K": [
                22.4024
            ],
            "Time_Working": [
                210.0
            ],
            "Temperature_F_Working": [
                72.05
            ],
            "Temperature_C_Working": [
                22.25
            ],
            "Cap_Reference_300": [
                12.0822
            ],
            "Frequency_Reference_300": [
                300.0
            ],
            "Temperature_C_Reference": [
                22.25
            ],
            "Cap_Reference_1K": [
                7.104
            ]
        }
    }
]

```

This is what the dubug is showing coming in after I decode the JSON.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4d0337390da172e0d34555a0dc84b139b5816a2d.png)

This is what the flow looks like hooked up to the debug.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d29d07146a7f953d4562cbb92b44479db62a50ec.png)

I am at a loss on what I need to adjust for the data to be accepted into InfluxDB.

Thanks for all of the help,

Derick

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [20 August 2019 20:38 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563/2 "2019-08-20T20:38:11Z")

</div>

Can you post your flow to show how you decode the JSON? Based on the screenshot of the debug node it appears to create a JavaScript object as intended, then literally creates a string of it. So what you see in the payload is the string representation of an array with objects.

---

<div class="post-metadata">

### Author: ![Axiom](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Axiom](https://discourse.nodered.org/u/Axiom)
#### Post date: [20 August 2019 20:41 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563/3 "2019-08-20T20:41:52Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/58dbde00ef9f391a6bb35e750cedebd32ce56e01.png)

I read in a post, or was just under the assumption, that the JSON needed to be decoded first.

Is that what you are asking for? I am still learning how all of this works.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 August 2019 21:04 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563/4 "2019-08-20T21:04:11Z")

</div>

I think you are a little confused about what JSON is. JSON is a method of encoding a javascript object as a string, so JSON is already a string. What you want to do first is to convert it to a javascript object (if what you have to start with is actually JSON). If you feed the incoming data into a debug node it will tell you at the top whether it is a string or an object. If it is a string then feed it into a JSON node to convert it to a javascript object.

---

<div class="post-metadata">

### Author: ![Axiom](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Axiom](https://discourse.nodered.org/u/Axiom)
#### Post date: [20 August 2019 21:30 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563/5 "2019-08-20T21:30:44Z")

</div>

I realized i was using a mqtt node that parsed json data.

I am now using the mqtt dynamic node hooked up as follows with these outputs.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9909ad605aa8a3483e26016a3d89038ea885f4bb.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0d52e8244da318850a56bd6f9b75426ab365fc00.png)

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [20 August 2019 23:32 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563/6 "2019-08-20T23:32:15Z")

</div>

Set the mqtt node to `a parsed json object`.

Your field formats are a bit strange, all single values seem to live in an array, you will have to fix that first and then you can connect it to the influx batch node.  
Then it should work.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [21 August 2019 10:47 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563/7 "2019-08-21T10:47:43Z")

</div>

Note that the timestamp needs to be nanoseconds for the influx batch node.

---

<div class="post-metadata">

### Author: ![matzeeg3](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@matzeeg3](https://discourse.nodered.org/u/matzeeg3)
#### Post date: [2 April 2020 06:25 UTC](https://discourse.nodered.org/t/passing-json-from-mqtt-into-influxdb/14563/8 "2020-04-02T06:25:33Z")

</div>

@Axiom do you have a solution for that?  
i have the same issue
