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
.
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.