question

hasangolshahri-7728 avatar image
0 Votes"
hasangolshahri-7728 asked ·

Json_Value get special character

Hi
declare @myfeature varchar(max) = '{"fieldterminator":",","rowterminator":"\n"}',@FeaturesForScript varchar(max)=''
set @FeaturesForScript += isnull(', FIELDTERMINATOR = ''' + JSON_VALUE(@myfeature,'$.fieldterminator') + '''','')
set @FeaturesForScript += ISNULL(',ROWTERMINATOR = ''' + JSON_VALUE(@myfeature,'$.rowterminator') + '''','')

select @FeaturesForScript

when I use "\n" the Json_Value can not get that character and this is empty
result show for me
, FIELDTERMINATOR = ',',ROWTERMINATOR = ' '
Is this Ok?

sql-server-general
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered ·

Try selecting from menu: Query, Results To, Results to Text, then execute the query. You will see the new-line corresponding to “\n”, but which is not visible in case of grid.

· 3 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

But I want get \n character for use in other script

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 hasangolshahri-7728 ·

It contains the character code 0A, which is also ‘\n’. If you need ‘\n’ as a text, you can try

declare @myfeature varchar(max) = '{"fieldterminator":",","rowterminator":"\\n"}

however it is not clear how do you want to use it.

1 Vote 1 ·

thank you very match
نوروزتان مبارک

0 Votes 0 ·