# Influx DB data insertion

**URL:** <https://discourse.nodered.org/t/influx-db-data-insertion/21185>\
**Category:** General\
**Created:** [3 February 2020 07:35 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185 "2020-02-03T07:35:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![neelanjan](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@neelanjan](https://discourse.nodered.org/u/neelanjan)\
**Post date:** [3 February 2020 07:35 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/1 "2020-02-03T07:35:52Z")

</div>

Hi,  
I want to parse the tag value=tag key pair and field value=field key pair from the payload and insert it influxdb measurement. Can anyone help me.  
Thanks

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 February 2020 08:24 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/2 "2020-02-03T08:24:40Z")

</div>

Well, you haven't told us what your input data looks like. Please try a debug msg and share the actual data. You probably need a JSON node to de-serialise the data but without more info, we can't provide better help.

---

<div class="post-metadata">

**Author:** ![neelanjan](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@neelanjan](https://discourse.nodered.org/u/neelanjan)\
**Post date:** [3 February 2020 08:40 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/3 "2020-02-03T08:40:54Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3e4b099d121a55385edbbb1bc47d67a64f08b65b.png) -----overall scheme  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7be5510217e2640c27233f66de358c420e4af76.png)---------json node settings  
please find the screenshots

same data is getting logged in to influx db. But in the value column, I am getting the full payload. I need to parse the data and make separate column for each tag.

Thanks

---

<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:** [3 February 2020 09:59 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/4 "2020-02-03T09:59:37Z")

</div>

Have you tried putting a change node in between JSON and influx? And in that change node modify the payload to the format you need. Beyond that, there’s still a lot we don’t know. Please read @TotallyInformation’s message above again and supply that if you’re looking for more detailed help.

---

<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:** [3 February 2020 10:05 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/5 "2020-02-03T10:05:56Z")

</div>

In particular show us what is coming out of the data collector function node and the json node.

---

<div class="post-metadata">

**Author:** ![neelanjan](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@neelanjan](https://discourse.nodered.org/u/neelanjan)\
**Post date:** [3 February 2020 10:38 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/6 "2020-02-03T10:38:55Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f38c800349dffcdf54f1341a5d3e2d88119d2d70.png)

json data

---

<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:** [3 February 2020 10:41 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/7 "2020-02-03T10:41:30Z")

</div>

Ahhh, so the data was deserialised already and adding a JSON node caused it to be serialised instead.

---

<div class="post-metadata">

**Author:** ![neelanjan](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@neelanjan](https://discourse.nodered.org/u/neelanjan)\
**Post date:** [3 February 2020 10:49 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/8 "2020-02-03T10:49:46Z")

</div>

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

and this is the data after collecting the raw data.....

my target is to put this data into influxdb with tag key and tag value pair

---

<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:** [3 February 2020 10:54 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/9 "2020-02-03T10:54:49Z")

</div>

Have you got the mqtt node set to parse the input as JSON? If not then I suggest you do that and then look at what is coming out of the mqtt. It should give you a javascript object rather than a string, then the rest should be much easier.  
By the way if you you want to write data at the current timestamp you don't need to add a timestamp, the influx node will do that for you.

---

<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:** [3 February 2020 11:13 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/10 "2020-02-03T11:13:44Z")

</div>

It took a few minutes, but now I understand what I'm looking at. Take a really close look at the `msg.payload` object in that photo. Your payload is an object containing 3 properties: `time`, which holds a timestamp, `topic`which holds the same topic as `msg.topic` and according to the image is `adc/ecu/site1`, and `payload`, which is a JSON string. So you have a mixture of serialised and unserialised data that is being passed to the JSON node, and since the outer part is unserialised the total gets serialised. Resulting in a single JSON string coming out of that node.

What you need to do is parse the contents of `msg.payload.payload`. Either by following Colin's instructions if you haven't done so yet, or by changing the code in the `data collector` function node. Next, your object should look like an actual object with nested properties. You can then use a change node to format the payload the way you want it to for inserting it to influxdb. However, keep in mind that passing it towards the JSON node will turn it into a JSON string if it was an object before, or from a JSON string to an object if it was a string already. You have to work out what/how it is yourself.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 April 2020 11:13 UTC](https://discourse.nodered.org/t/influx-db-data-insertion/21185/11 "2020-04-03T11:13:55Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
