[fpc-pascal] JSON and UTF8

Ludo Brands ludo.brands at free.fr
Tue Jul 10 09:32:57 CEST 2012

> Following up on bug 22310 http://bugs.freepascal.org/view.php?id=22310
> I enabled the use of UTF8 in the FPC JSON support.
> The constructors of the JSON parser/scanner now accept an 
> extra argument 
> UseUTF8 which tells them to convert JSON strings to UTF8, not 
> the system codepage.
I don't understand why you want to keep buggy behavior for backwards
compatibility. I explain:
StringToJSONString doesn't do any character conversion except for some
special characters. The json spec rfc4627 par 3 says: "JSON text SHALL be
encoded in Unicode.  The default encoding is UTF-8." Since no conversion is
done logic says that fpjson expects unicode. Since TJSONStringType =
AnsiString, UTF-8 is the only unicode encoding possible. So I don't
understand why writing a TJSONStringType has to be utf8 to be compliant with
the spec and with the outside world and when reading the same string back it
is converted in system encoding. 
If system encoding support is needed then StringToJSONString should do also
a system to utf8 encoding. 


More information about the fpc-pascal mailing list