So I am generating a JSON file from SQL server 2016 using 'FOR JSON'
I have used JSON_QUERY to wrap queries to prevent the escape characters from appearing before the generated double quotes ("). This worked correctly except they are still showing up for the forward slashes (/) on the formatted dates.
One thing to note is that I am converting the datetime objects in SQL using the following method CONVERT(VARCHAR, [dateEntity], 101)
An example (This is a subquery)
JSON_QUERY((
SELECT [LegacyContactID]
,[NameType]
,[LastName]
,[FirstName]
,[Active]
,[Primary]
,CONVERT(VARCHAR,[StartDate],101) AS [StartDate]
,CONVERT(VARCHAR,[EndDate],101) AS [EndDate]
FROM [LTSS].[ConsumerFile_02_ContactName]
WHERE [LegacyContactID] = ContactList.[LegacyContactID]
FOR JSON AUTO, WITHOUT_ARRAY_WRAPPER
)) AS ContactName
And the result will be
"ContactName": {
"LegacyContactID": "123456789",
"NameType": "Name",
"LastName": "Jack",
"FirstName": "Apple",
"Active": true,
"Primary": true,
"StartDate": "04\/01\/2016",
"EndDate": "04\/30\/2016"
}
I have the whole query wrapped in JSON_QUERY to eliminate the escaping but it still escapes the forward slashes on the dates.
I also have passed the dates as strings without the conversion and still get the same results.
Any insight?