I have issue with SQL Server and JSON :/
There are a lot of JSON strings coming from a remote database (which I only have read permission). The problem is that all of them are parsed into unicodes and I don't know how to turn them into UTF-8 !
Take a look at this JSON for example:
{
"0":{
"id":1,
"name":"\\u062a\\u0646"
},
"1":{
"id":2,
"name":"\\u0628\\u0633\\u062a\\u0647 10\\u062a\\u0627\\u06cc\\u06cc"
},
"2":{
"id":3,
"name":"\\u0639\\u062f\\u062f 10\\u062a\\u0627\\u06cc\\u06cc"
},
"5":{
"id":6,
"name":"\\u0639\\u062f\\u062f 1000\\u062a\\u0627\\u06cc\\u06cc"
},
"6":{
"id":7,
"name":"\\u06a9\\u06cc\\u0644\\u0648\\u06af\\u0631\\u0645"
}
}
As you can see field name
is parsed into unicode. I did this to extract data into a table:
SELECT Units.*
FROM OPENJSON(@Json) AS i
CROSS APPLY OPENJSON(i.[value]) WITH (
[Id] INT '$.id',
[Name] NVARCHAR(MAX) '$.name'
) AS Units
It will then show something like this as result:
- Id: 1, Name: \u062a\u0646
- Id: 2, Name: \u0628\u0633\u062a\u0647 10\u062a\u0627\u06cc\u06cc
- ...
But I need something like this as result:
- Id: 1, Name: تن
- Id: 2, Name: عدد 10تایی
- ...