How to remove invisible characters in JSON

I am querying a json which is returned with invisible characters at the beginning specifically 0xef, 0xbb, 0xbf in UTF8, I have tried replacing them in string from with replace with the code:

clean = replace(unclean, “ï”=>"")
clean = replace(clean, “»”=>"")
clean = replace(clean, “¿” =>"")

I am wondering what the best way to remove these characters is?

Your approach should work. Are there any issues?

You can also do

clean = replace(unclean, Char(0xef)=>"")
1 Like

Another possible way is

julia> unclean = "abc¿def»ghiïjkl"
"abc¿def»ghiïjkl"

julia> clean = filter(!in(('ï', '»', '¿')), unclean)
"abcdefghijkl"

Note, I haven’t benchmarked anything.

2 Likes