If you had a newline, you would get "\n"
.
>perl -MJSON -E"say encode_json [ chr(0x0A) ]"
["\n"]
You don't have a newline. You have \
followed by n
.
>perl -MJSON -E"say encode_json [ chr(0x5C).chr(0x6E) ]"
["\\n"]
The \
must be escaped, or two string above would both return the same thing, which means that one of them would get decoded wrong.
You can verify the encoding is correct by seeing if you get back the original string after decoding.
>perl -MJSON -E"print encode_json [ chr(0x0A) ]" |
perl -MJSON -nE"say sprintf '%v02X', decode_json($_)->[0]"
0A
>perl -MJSON -E"print encode_json [ chr(0x5C).chr(0x6E) ]" |
perl -MJSON -nE"say sprintf '%v02X', decode_json($_)->[0]"
5C.6E