1

I have following statement that I am trying to execute in Sql Server 2016 CTP 3:

DECLARE @json nvarchar(max)

set @json = '[ 
   { "name": "John" },
   { "name": "Jane", "surname": "Doe" }
]'

select
    'othervalue' as o,
    @json as j
for json path

The problem is when I execute these statements I get the following Json string (with escaped characters):

[{"o":"othervalue","j":"[ \r\n   { \"name\": \"John\" },\r\n   { \"name\": \"Jane\", \"surname\": \"Doe\" }\r\n]"}]

My question is how can select a Json string with a select statement correctly (without escaped characters).

Thanks

1 Answer 1

2

Wrap @json variable with JSON_QUERY:

select
     'othervalue' as o,
      JSON_QUERY(@json) as j
for json path

See frequently asked questions on MSDN https://msdn.microsoft.com/en-us/library/mt631706.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.