this question has answer here:
is there anyway in javascript:
$ cat test.json {"body":"\u0000"} $ python3 -c 'import json; print(json.load(open("test.json", "r")))' {'body': '\x00'}
notice, data above 1 \
(does not need escaped). have following situation in javascript:
json.parse('{"body":"\\u0000"}') // works json.parse('{"body":"\u0000"}') // not work
with potentially utf-8 data comming binary source (websocket), can data processed directly in first python example above?
string characters \u0000
through \u001f
considered control characters, , according rfc-7159 not allowed characters use in json , must escaped, stated in section 7.
what trying put unescaped control characters json, not acceptable, have escape first, non of languages accept it, python.
the correct answer place utf-8 encoded value string containing json format.
this correct json, , parsed json parser in language, in javascript:
{"body":"\u0000"}
this incorrect json (consider [nul]
nul control character, cannot represented in text):
{"body":"[nul]"}
that's why json.parse('{"body":"\\u0000"}')
works , json.parse('{"body":"\u0000"}')
doesn't.
hope, clarifies what's wrong test.
Comments
Post a Comment