'à' french character display using JSON shows error

509 Views Asked by At

I have a french character (à) in my JSON String 'd'instruments cordes à'. But the (à) character shows JSON error when displaying. I want to display the exact character in my UI.

2

There are 2 best solutions below

0
On

You really should provide more details. As of now, it's unclear whether you are generating or parsing your JSON in the database.

Regardless, below is a short sample demonstrating that "à" is not a special character in any way. Compare the code below with yours, and especially pay attention to the difference between varchar and nvarchar. I think that's where your problem is.

declare @j nvarchar(max);

declare @t table (
    Id int,
    Value nvarchar(100),
    Country varchar(50)
);

insert into @t (Id, Value, Country)
values
    (634149, N'd''instruments cordes à', 'America');

-- Shows data in the table
select * from @t;

set @j = (
    select *
    from @t t
    for json path, without_array_wrapper
);

-- Shows generated JSON
select @j as [GeneratedJSON];

-- Shows JSON query output
select *
from openjson(@j) with (
    Id int '$.Id',
    Value nvarchar(100) '$.Value',
    Country varchar(50) '$.Country'
) j;
0
On

Make sure your page contains the following meta tag to support international characters.

<meta charset="utf-8" />