Is there a standard for embedding JSON in HTML?

前端 未结 4 1064
借酒劲吻你
借酒劲吻你 2021-01-31 19:37

I would like to embed JSON in HTML. The most elegant solution I have found makes use of the script-tag and the mime media type application/json.

<
4条回答
  •  心在旅途
    2021-01-31 20:36

    What you suggest is absolutely correct. The type attributes of the script tag must be a valid MIME descriptor. According to the official JSON RFC section 6 "IANA Considerations":

    The MIME media type for JSON text is application/json.
    Type name: application
    Subtype name: json

    So your HTML is valid:

     
    

    And, no, there are no additional risks involved in doing this.

提交回复
热议问题