Are JSONOptions broken?

frame frame86 at live.com
Sat Nov 28 14:21:05 UTC 2020


I need to encode a key as string through json.

This throws an UTF-exception:

auto json = JSONValue(cast(char[])[0x00, 0x7D, 0xFE, 0xFF, 0x14, 
0x32, 0x43, 0x10]);
writeln(json.toString(JSONOptions.escapeNonAsciiChars));

Makes no sense. Either the bytes should be properly escaped or 
there should not be any option if a string want to be converted 
to UTF anyway.

This is also fun:

auto json = 
JSONValue(r"\u0000\u007D\u00FE\u00FF\u0014\u0032\u0043\u0010");
assert(json.toString() == 
json.toString(JSONOptions.doNotEscapeSlashes));

and ends with:

"\\u0000\\u007D\\u00FE\\u00FF\\u0014\\u0032\\u0043\\u0010"


More information about the Digitalmars-d-learn mailing list