2

I have inserted some test data like below:

INSERT INTO tblDataInfo (lookupkey, lookupvalue, scope) 
VALUES ('diskname', '/dev/sdb', 'common')

yours sincerely

I wanted to query this data and like to obtain the query output in JSON format.

I have used the query

select lookupvalue as 'disk.name' 
from tblDataInfo 
where lookupkey = 'diskname' FOR JSON PATH;

This query returns

[{"disk":{"name":"\/dev\/sdb"}}]

which is escaping all my forward slashes (/) using the escape character (\). How can I have my output not to put escape-character (\)?

1 Answer 1

2

This query returns result that you need:

select json_query ('{"name":"' + lookupvalue + '"}') as 'disk'
from tblDataInfo 
where lookupkey = 'diskname'
for json path;

Not the answer you're looking for? Browse other questions tagged or ask your own question.