javascript - Null character within json - Stack Overflow

After an hour of googling I am kind of embarrassed to ask this. But are null characters (ascii null or

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.

Share Improve this question asked May 14, 2017 at 23:13 user2882307user2882307 8
  • 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
 |  Show 3 more ments

1 Answer 1

Reset to default 5

According 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

相关推荐

  • javascript - Null character within json - Stack Overflow

    After an hour of googling I am kind of embarrassed to ask this. But are null characters (ascii null or

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信