Want to prepare json without columns those are empty.
Here is detail example
MY_TABLE
=================
id , Name
=================
1 , Ali
2 ,
3 , jhon
=================
SQL STATEMENT FOR JSON
(SELECT [Id],[Name] FROM My_Table)
FOR JSON PATH
SQL RESULT:
[{
"Id": 1,
"Name": "Ali"
}, {
"Id": 2,
"Name": ""
}, {
"Id": 3,
"Name": "Jhon"
}]
But i want to exclude element which has no value like No "Name":"" Element in following result:
[{
"Id": 1,
"Name": "Ali"
}, {
"Id": 2,
}, {
"Id": 3,
"Name": "Jhon"
}]
EDITED: Please Note, i can apply CASE or UDF to convert empty values into null and null value may remove from json but it will slow the overall performance with large number of records therefore looking smart solution.