I have to write a query to retrieve data in single json object format.
I have mixed columns. few of them are JSON and few of them are numerical values. While retrieving data i should convert each row to single JSON object. My query is giving me single object but it is giving me results with \\ slashes. Can someone help me in reformatting the below query which should exclude the slashes while formatting each row into single JSON object.
(select
(select
p.personReferenceNumber as personReferenceNumber,
personIdentity as personIdentity,
isnull([name],'') as [name],
p.gender as gender,
isnull(p.birthDateHijri,'') as birthDateHijri,
isnull(p.birthDateGregorian,'') as birthDateGregorian,
isnull(p.liveStatus,'') as liveStatus,
isnull(p.nationality,'') as nationality,
isnull(p.specific,'') as specific,
isnull(p.isDeleted,'') as isDeleted,
isnull(p.sessionId,'') as sessionId,
isnull(p.insertedBy,'') as insertedBy,
isnull(p.insertedTimeStamp,'') as insertedTimeStamp,
isnull(p.updatedBy,'') as updatedBy,
isnull(p.updatedTimestamp,'') as updatedTimestamp
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER) AS person
from person p)
Output:
{\"messageId\":\"f616dbd3-1352-404b-939e-5b12f90b57fe\",
\"transactionRowId\":594834948322275328,
\"personId\":\"bebox13\",
\"idType\":2,\"issueDateHijri\":14400203,
\"issueDateGregorian\":\"2019-04-12T03:00:00\",
\"expiryDateHijri\":14400104,
\"expiryDateGregorian\":\"2019-04-12T03:00:00\",
\"issuePlace\":[\"Update\",
\"Update\"]}",
"name":
"{\\\"messageId\\\":\\\"f616dbd3-1352-404b-939e-5b12f90b57fe\\\",
\\\"transactionRowId\\\":594834948322275328,
\\\"firstName\\\":[\\\"Update\\\",\\\"Update\\\"],\\\"secondName\\\":[\\\"Update\\\",\\\"Update\\\"],\\\"thirdName\\\":[\\\"Update\\\",\\\"Update\\\"],\\\"familyName\\\":[\\\"Update\\\",\\\"Update\\\"]}"
SELECTis returning the result of yourFOR JSON.