TypeError: Cannot convert undefined or null to object

My data is a json format. However, there are some null in my data. How can I fix the problem. Can I change null to string. How can I change by using java?

You will need to give us much more to go on than this. We have no idea what your data looks like.

Guessing from the title, I'd say that you have misunderstood or mis-written a property path such that it doesn't actually exist. So the question of how to change null to a string is not relevant.

Also, the query about Java is also not relevant - Node-RED uses JavaScript which is an entirely different language.

@TotallyInformation Thanks for your reply.
This is my data. I would want to process insert query. However, it appears TypeError when I debug.

var keyName = Object.keys(msg.data)[msg.start] ;
var Changetime = msg.data[keyName].Changetime;
var Class3 = msg.data[keyName].Class3;
var Class2 = msg.data[keyName].Class2;
var Class1 = msg.data[keyName].Class1;
var Py = msg.data[keyName].Py;
var Px = msg.data[keyName].Px;
var Gov = msg.data[keyName].Gov;
var Picdescribe3 = msg.data[keyName].Picdescribe3;
var Picture3 = msg.data[keyName].Picture3;
var Picdescribe2 = msg.data[keyName].Picdescribe2;
var Picture2 = msg.data[keyName].Picture2;
var Picdescribe1 = msg.data[keyName].Picdescribe1;
var Picture1 = msg.data[keyName].Picture1;
var Opentime = msg.data[keyName].Opentime;
var Zipcode = msg.data[keyName].Zipcode;
var Add = msg.data[keyName].Add;
var Tel = msg.data[keyName].Tel;
var Description = msg.data[keyName].Description;
var Toldescribe = msg.data[keyName].Toldescribe;
var Name = msg.data[keyName].Name;
var Id = msg.data[keyName].Id;
msg.topic = "INSERT INTO travel (Changetime, Class3, Class2, Class1, Py, "+
"Px, Gov, Picdescribe3, Picture3, Picdescribe2, Picture2, Picdescribe1, Picture1, Opentime, Zipcode, Add, Tel, Description, Toldescribe, Name, Id) VALUES ('" + Changetime + "', '" + Class3 + "', '" + Class2 + "', '" + Class1 +
"', '" + Py + "', '" + Px + "', '" + Gov + "', '" + Picdescribe3 + "', '" + Picture3 + "', '" + Picdescribe2 + "', '" + Picture2 + "', '" + Picdescribe1 + "', '" + Picture1 + "', '" + Opentime + "', '" + Zipcode + "', '" + Add + "', '" + Tel + "', '" + Description + "', '" + Toldescribe + "', '" + Name + "', '" + Id + "')";

msg.start = msg.start + 1;
return msg;

This is one of my Json data.

[{"Changetime":"2017/07/05 13:15:08","Class3":"","Class2":"","Class1":"10","Py":"25.22186","Px":"121.64589","Gov":"382000000A","Picdescribe3":"123","Picture3":"http://tour.ntpc.gov.tw/Content/Upload/Place/20150709115909.jpg","Picdescribe2":"234","Picture2":"http://tour.ntpc.gov.tw/Content/Upload/Place/20150709115902.jpg","Picdescribe1":"345","Picture1":"http://tour.ntpc.gov.tw/Content/Upload/Place/20150709115854.jpg","Opentime":"09ļ¼š00-24ļ¼š00","Zipcode":"208","Add":"5345","Tel":"886-2-24082628","Description":"a good place \r\n\r\n the place is awesome","Toldescribe":"It has been ten years","Name":"new york","Id":"C1_382000000A_102485"}]

When posting, please wrap code with back-tags so that it is readable.

You will need to add a debug node before this function so that you can see what the correct layout is for the msg you are passing in.

I rather suspect that where you have used msg.data you might have meant msg.payload.data? But I can't tell.

I see. I would keep in mind.

Yes, msg.data meant msg.payload.data. This is the data before process insert query. However, it is still error.

var obj = msg.payload;
if (obj.retCode == "1")
{
msg.repetitions = Object.keys(obj.retVal).length;
msg.data = obj.retval;
msg.start = 0;
}

return msg;

What is the exact full error you are getting?

That doesn't seem to match the data you gave earlier.

@TotallyInformation Thanks for your help. I had fixed it. Nonetheless, I guess that there are some problem in my database ,can you help me find the problem?

   name          type

1 Changetime         datetime
2 Class3                 varchar(2)
3 Class2                 varchar(2)
4 Class1                  varchar(2)
5 Py                         varchar(20)
6 Px                         varchar(20)
7 Gov                       varchar(20)
8 Picdescribe3         text
9 Picture3                 varchar(200)
10 Picdescribe2       varchar(50)
11 Picture2               varchar(200)
12 Picdescribe1       text
13 Picture1               varchar(200)
14 Opentime             varchar(60)
15 Zipcode                 varchar(10)
16 Add1                     varchar(40)
17 Tel                         varchar(40)
18 Description           text
19 Toldescribe           varchar(500)
20 Name                   varchar(30)
21 Id                           varchar(50)

And there is a new error.

"Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Add, Tel, Description, Toldescribe, Name, Id) VALUES ('2017/09/11 12:43:21', '',' at line 1"

There is a new error I get.

"Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Add, Tel, Description, Toldescribe, Name, Id) VALUES ('2017/09/11 12:43:21', '',' at line 1"

It would help if you wired a debug node next to whatever node you have trying to perform that query so we can see the full SQL query you are trying to perform. It is then a matter of spotting the syntax error.

1 Like

I notice that you are trying to write to a column called Add, but there is no such column in the database, though that would not give a syntax error.

You have "Add1" in your table definition.