Closed silviucpp closed 2 years ago
As a note php jsone_encode it's working fine:
<?php
$return = json_encode(
["s1" => "\\u001b test 1 2 3"],
JSON_PRETTY_PRINT);
echo $return;
{
"s1": "\\u001b test 1 2 3"
}
Also JS encoder works fine:
const obj = {s1: "\\u001b test 1 2 3"};
JSON.stringify(obj);
{"s1":"\\u001b test 1 2 3"}
Hi,
It's expected behavior as the character \
in JSON strings should be escaped as described in the JSON specification.
You're giving Original
containing an already escaped UTF-8 string, but it's needed to pass as a non-escaped one instead (to prevent double escaping) as follows:
> Original = [{<<"s1">>, <<"\e test 1 2 3">>}].
> jsone:encode(Original).
<<"{\"s1\":\"\\u001b test 1 2 3\"}">>
> jsone:decode(jsone:encode(Original)).
#{<<"s1">> => <<"\e test 1 2 3">>}
BTW, I tried running the JS version on a Node.js shell. The result seemed to match the jsone's result.
$ node --version
v17.2.0
$ node
> const obj = {s1: "\\u001b test 1 2 3"};
> JSON.stringify(obj);
'{"s1":"\\\\u001b test 1 2 3"}'
Thanks for clarifications !
Silviu
Hello,
First I'm not sure this is a bug in the library. But I will appreciated help from somebody on this issues I'm facing. I have a proplists in
Original
and I'm expecting the encoding to produceExpected
binary. But I have no clue what to do to generate this output.When I encode the proplists the
\
char from the unicode code are double encoded and everything gets broken.Output:
Kind regards, Silviu