2

Default charset in base is Windows1251, but when I use "for json" statement, result presents in "utf8"

Is it possible convert some column to ut8, using sql?

I try this code

select 
  1 as "tag",
  null as "parent",
  "period" as "!1!period",
  "nazva" as "!1!nazva",
  "DogovorNumber" as "!1!DogovorNumber"
  from "dba"."Myk_Orgs_for_1C"(@cmonth = 3,@cyear = 2022)
  order by 3 asc for json explicit

But my columns values shown like this "nazva":"ГОРОЯН НАIРА"

jarlh
  • 42,561
  • 8
  • 45
  • 63
Юрій
  • 21
  • 3
  • You face a [mojibake](https://en.wikipedia.org/wiki/Mojibake) case (*example in Python for its universal intelligibility*): `'ГОР\xa0РћРЇРќ РќРђIР\xa0Рђ'.encode('cp1251').decode('utf-8')` returns `ГОРОЯН НАIРА`. Here `\xa0` is ` ` (U+00A0, *No-Break Space*)… – JosefZ Dec 19 '22 at 10:39

1 Answers1

1

You can workaround the encoding issue with output statement:

select 
  1 as "tag",
  null as "parent",
  "period" as "!1!period",
  "nazva" as "!1!nazva",
  "DogovorNumber" as "!1!DogovorNumber"
  from "dba"."Myk_Orgs_for_1C"(@cmonth = 3,@cyear = 2022)
  order by 3 asc for json explicit
;
output to 'C:\\out.json' format text escapes on escape character '\' delimited by '' encoding 'CP-1251'
Vadim Zin4uk
  • 1,716
  • 22
  • 18