# Writing specific data from parsed json object into influxdb 1.8x

**URL:** <https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412>\
**Category:** General\
**Created:** [11 February 2024 09:57 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412 "2024-02-11T09:57:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hugo99](https://avatars.discourse-cdn.com/v4/letter/h/a8b319/32.png) [@hugo99](https://discourse.nodered.org/u/hugo99)\
**Post date:** [11 February 2024 09:57 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412/1 "2024-02-11T09:57:55Z")

</div>

Dears

I am calling data from my fronius inverter via a http request node (solar api) and receive a parsed json object:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/90bb55b0e7c907fd90109be59582abb0c46de048.png)

I am interested into writing "P\_GRID" into the measurement "P\_GRID" into field "default"  
in this case the value 496,8

so far I was able to get this data into an object with this function:

msg.payload = [  
{measurement: "P\_PV2",  
fields: {  
P\_Grid: msg.payload.Body.Data.Site.P\_Grid,  
},},]  
return msg;

resulting in:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/dba8de4920a59cd0abc2c786c3d6b7cf40bc8906.png)

from here i am unable to write the number (!) 496,8 into the field "default" of measurement "energy"

I think i need to convert 496,8 into a number and then have a function node write this number into the correct measurement and field

any help is greatly appreciated 🙂

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 February 2024 10:01 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412/2 "2024-02-11T10:01:56Z")

</div>

> [@hugo99](#):
>
> msg.payload = [  
> {measurement: "P\_PV2",  
> fields: {  
> P\_Grid: msg.payload.Body.Data.Site.P\_Grid,  
> },},]

Try

```auto
msg.payload = [{
  measurement: "P_PV2",
  fields: {
    P_Grid: +msg.payload.Body.Data.Site.P_Grid,
  }
}]

```

---

<div class="post-metadata">

**Author:** ![hugo99](https://avatars.discourse-cdn.com/v4/letter/h/a8b319/32.png) [@hugo99](https://discourse.nodered.org/u/hugo99)\
**Post date:** [11 February 2024 10:23 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412/3 "2024-02-11T10:23:21Z")

</div>

thanks!  
I did as you suggested:

> msg.payload = [{  
> measurement: "P\_Grid Stromverbrauch",  
> fields: {  
> default: +msg.payload.Body.Data.Site.P\_Grid,  
> }  
> }]  
> return msg

If I don't specify a measurement in my influxdb node I get:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8f73fa6305c2fd21c0170017a01ac9fa01995ed6.png)  
I expected the measurement to be specified in the function above

If i do specify "P\_Grid Stromverbrauch" in the influxdb node as measurement I get:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a6f4e138226c0fa1dcce6af85b83fcb7f29d34e3.png)

---

<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:** [11 February 2024 10:24 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412/4 "2024-02-11T10:24:38Z")

</div>

In the help text for the influx Out node it these options for what you need in msg.payload:

If **msg.payload** is an object containing multiple properties, the fields will be written to the measurement.  
If **msg.payload** is an array containing two objects, the first object will be written as the set of named fields, the second is the set of named tags.  
Finally, if **msg.payload** is an array of arrays, it will be written as a series of points containing fields and tags.

Your payload is an array of one object so does meet any of those.  
Also it says that to pass the measurement the message you should use msg.measurement.

If you want to write the value into the field "default", which seems strange, then you need msg.payload just to contain  
`{default: 496.8}`  
and you need msg.measurement to contain the measurement name. Note that the value 496.8 must be a number not a string. You can use that by saying something like  
`msg.payload = {default: Number(msg.payload.Body.Data.Site.P_Grid)}`

Normally the field would either be something like "P\_GRID" or "value".

---

<div class="post-metadata">

**Author:** ![hugo99](https://avatars.discourse-cdn.com/v4/letter/h/a8b319/32.png) [@hugo99](https://discourse.nodered.org/u/hugo99)\
**Post date:** [11 February 2024 10:33 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412/5 "2024-02-11T10:33:51Z")

</div>

i am looking into this, tnx!  
the name "default" is strange indeed, but i am referring to an existing database, which i didn't set up

---

<div class="post-metadata">

**Author:** ![hugo99](https://avatars.discourse-cdn.com/v4/letter/h/a8b319/32.png) [@hugo99](https://discourse.nodered.org/u/hugo99)\
**Post date:** [11 February 2024 11:21 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412/6 "2024-02-11T11:21:28Z")

</div>

it is working 🙂  
here is the working function:

```auto
msg.measurement = "P_PV2";
msg.payload = [{
P_Grid: Number(msg.payload.Body.Data.Site.P_Grid)
},
{}];
return msg;

```

I parsed correctly for the desired value "P\_Grid"  
I converted P\_Grid into a number  
I am writing to measurement "P\_PV2"

tnx to all of you for your 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:** [11 February 2024 11:40 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412/7 "2024-02-11T11:40:11Z")

</div>

Since there are not any tags you should be able to use just

```auto
msg.measurement = "P_PV2";
msg.payload = {
  P_Grid: Number(msg.payload.Body.Data.Site.P_Grid)
}
return msg;

```

---

<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:** [25 February 2024 11:41 UTC](https://discourse.nodered.org/t/writing-specific-data-from-parsed-json-object-into-influxdb-1-8x/85412/8 "2024-02-25T11:41:05Z")

</div>

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