I export data from MySQL into a JSON file, but there is an error due to null value. How do I handle this?
SQL query:
select industry, ... from table1;
where some of the industry gives null value:
JSON format
[{"industry":"entertainment", ...}, {"industry":"", ...}, {"industry":NULL, ...}]
The error is due to the 3rd object value in the array (i.e. NULL)
I tried:
select cast(industry as char), ... from table1;
Unfortunately, it still gives the same error. Because in the MySQL cell, it shows NULL value.
Thanks!
Update:
As there will be other variables in each object, I would like to change the NULL value in SQL either to "" or "NULL".
You can use ifnull
to cast your NULL
values
select ifnull(industry, '') from table1;