Here is my code:
DECLARE @info NVARCHAR(MAX) = '{"searchQuery":{"reportType":"ReportedHcEcg"},"pageQuery":{"pageNumber":1,"pageSize":10,"sortColumnName":"Urgent, UploaDateTime","sortOrder":"Desc"}}'
SET @info = JSON_MODIFY(@info, '$.searchQuery.reportType', NULL)
SELECT @info
When I try to remove the reportType field in 2nd line of code my output should be the one by removing reportType from searchQuery like below
{"searchQuery":{},"pageQuery":{"pageNumber":1,"pageSize":10,"sortColumnName":"Urgent, UploaDateTime","sortOrder":"Desc"}}
Instead of that it is like below
{"searchQuery":{"pageSize":10,"sortColumnName":"Urgent, UploaDateTime","sortOrder":"Desc"}}
I can not understand this behavior of SQL Server. Is there any help for this?
SELECT JSON_MODIFY('{"a":{"b":""},"c":{"d":"","e":""}}', '$.a.b', NULL)is{"a":{"e":""}}, whileSELECT JSON_MODIFY('{"a":{"b":""},"c":{"d":""}}', '$.a.b', NULL)(note: only one property on the second object) gives the correct{"a":{},"c":{"d":""}}. Ifstrictis used in the path, both cases correctly seta.btonull, so it seems like only deleting misfires.SELECT JSON_MODIFY('{"a":{"b":"","c":""},"d":{"e":"","f":""}}', '$.a.b', NULL)yields the correct{"a":{"c":""},"d":{"e":"","f":""}}, andSELECT JSON_MODIFY('{"a":{"b":"","c":""},"d":{"e":"","f":""}}', '$.a.c', NULL)yields{"a":{"b":""},"d":{"e":"","f":""}}. This suggests some (fairly complicated) workarounds by adding dummy members and testing for emptiness.