After an hour of googling I am kind of embarrassed to ask this. But are null characters (ascii null or \0
) allowed within json? I can find that it's not allowed within json strings but my question is if it is allowed withing the body at all.
So is something like this valid:
{
"MyKey": "MyValue"\0
}
Where the \0
is an actual null character not an escaped one.
After an hour of googling I am kind of embarrassed to ask this. But are null characters (ascii null or \0
) allowed within json? I can find that it's not allowed within json strings but my question is if it is allowed withing the body at all.
So is something like this valid:
{
"MyKey": "MyValue"\0
}
Where the \0
is an actual null character not an escaped one.
- 1 @Faust Read the question that isn't even close to what I'm asking – user2882307 Commented May 14, 2017 at 23:16
- There are lots of online json validators – charlietfl Commented May 14, 2017 at 23:19
- @charlietfl Which may or may not be correct. See for instance jsonlint. where you can put in null chars into a json string it happily say it's valid when it isn't. – user2882307 Commented May 14, 2017 at 23:20
- @charlietfl I don't think it's so hard to put a literal null character into the above "MyValue" string and see it for yourself.. – user2882307 Commented May 14, 2017 at 23:24
-
2
While the
\0
escape sequence is not permitted in JSON strings, there is nothing in the specification that prevents one from using the\u0000
hex escape sequence to represent the NUL character within a string. – Emile Cormier Commented Jan 8, 2020 at 3:58
1 Answer
Reset to default 5According to JSON specification JSON cannot contain \0
, only spaces between tokens:
Insignificant whitespace is allowed before or after any of the six
structural characters.
ws = *(
%x20 / ; Space
%x09 / ; Horizontal tab
%x0A / ; Line feed or New line
%x0D ) ; Carriage return
https://www.rfc-editor/rfc/rfc7159
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744135762a4560049.html
评论列表(0条)