# Error in creating CSV from json

**URL:** https://discourse.nodered.org/t/error-in-creating-csv-from-json/4783
**Category:** General
**Created:** [12 November 2018 05:49 UTC](https://discourse.nodered.org/t/error-in-creating-csv-from-json/4783 "2018-11-12T05:49:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AnuragSinghChaudhary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anuragsinghchaudhary/32/25809_2.png) [@AnuragSinghChaudhary](https://discourse.nodered.org/u/AnuragSinghChaudhary)
#### Post date: [12 November 2018 05:49 UTC](https://discourse.nodered.org/t/error-in-creating-csv-from-json/4783/1 "2018-11-12T05:49:41Z")

</div>

I'm using 4 sensors(DHT11,MQ135,YL69,LDR) with arduino, I'm able to get the values on debug screen in json string, while creating csv, i'm getting only DHT11 values (humidity & temperature) other values are coming as

11/12/2018;11:01:16 AM;66;25;undefined;undefined;undefined

_Here is the code for creating csv_

var date = new Date (). toLocaleDateString ();  
var time = new Date (). toLocaleTimeString ();

var output = date + ";" + time + ";" + msg.payload.Humidity + ";" + msg.payload.Temperature + ";" + msg.payload.AnalogValue + ";" + msg.payload.moisture + ";" + msg.payload.Airquality;  
msg.payload = output;  
return msg

_Arduino code_

#include "dht.h"  
#define dht\_apin A0 // Analog Pin sensor is connected to

dht DHT;

void setup(){

Serial.begin(115200);  
delay(500);//Delay to let system boot  
[//Serial.println](https://Serial.println)("DHT11 Humidity & temperature Sensor\n\n");  
delay(5000);//Wait before accessing Sensor

}//end "setup()"

void loop(){  
//Start of Program

```
DHT.read11(dht_apin);

unsigned int AnalogValue;

AnalogValue = analogRead(A1);

int moisture = analogRead(A2);

int Airquality = analogRead(A3);

//Serial.print("humidity = ");
//Serial.print(DHT.humidity);
//Serial.print("% ");
//Serial.print("temperature = ");
//Serial.print(DHT.temperature); 
//Serial.println("C ");

Serial.print ("{\"Temperature\":");
Serial.print(DHT.temperature);
Serial.print (",");
Serial.print ("\"Humidity\":");
Serial.print(DHT.humidity);
Serial.print (",");

Serial.print ("\"Moisture\":");
Serial.print(moisture);
Serial.print (",");

Serial.print ("\"AirQuality\":");
Serial.print(Airquality);
Serial.print (",");

Serial.print ("\"EC\":");
Serial.print(AnalogValue);
Serial.println ("}");

delay(5000);//Wait 5 seconds before accessing sensor again.

```

//Fastest should be once every two seconds.

}// end loop()

---

<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: [12 November 2018 07:02 UTC](https://discourse.nodered.org/t/error-in-creating-csv-from-json/4783/2 "2018-11-12T07:02:55Z")

</div>

> [@AnuragSinghChaudhary](#):
>
> 11/12/2018;11:01:16 AM;66;25;undefined;undefined;undefined

Your undefined values are undefined. That means that things like `msg.payload.moisture` don't actually exist. Use the copy path facility on debug output to get the correct path to the property.

Also, CSV = "Comma" separated. Not generally ";" separated. And you may need to surround the date and time with double quotes in the output. It is generally best to use the CSV node to produce CSV formatted output that you can then save to file as it will take care of the formatting for you.
