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"

Reply via email to