Sorry if the title is a little bit confusing but will try to give a real example to my problem.
So I am trying to use the new Sql Server JSON supporting query syntax.
I do a left join between two tables and of course if the second table does not contain any element I get null values for second table.
select a.Id, b.RefId, b.Name
from table1 a
left join table2 b
on a.Id = b.RefId
The query is simple just to give the idea what I am doing.
If I add FOR JSON AUTO, WITHOUT_ARRAY_WRAPPER part at the end of the query I get a nice json string but, if there is no element in table2 matching to any element in table1 then I get and array with an empty object.
Something like below:
{
"Id": 1,
"b":[{}]
}
This is fine but I want to completely remove the empty object from b element, so, I could have something like this:
{
"Id": 1,
"b":[]
}
Is this possible to do in Sql Server instead of writing a custom converter in c# to remove those fake elements ?