Which content-type(MIME type) to use for JSON data
Problem :
Your program sitting in your web server is pumping out JSON data. You need to set the correct header Content-Type
or MIME type.
Which content-type should you use?
Solution :
For JSON:
Content-Type: application/json
Example data :
{ "Id": 1, "Name": "Boo", "Job": "CEO" }
For JSON-P and for passing a JavaScript object literal :
Content-Type: application/javascript
Example data :
functionCall({ "Id": 1, "Name": "Boo", "Job": "CEO" });
To set Header example in Golang :
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Type", "application/javascript")
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+48.3k Golang : How to convert JSON string to map and slice
+9.3k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+9.2k Golang : Intercept and compare HTTP response code example
+12.8k Golang : Remove or trim extra comma from CSV
+5.4k Golang : Reclaim memory occupied by make() example
+7.2k Golang : Array mapping with Interface
+25.8k Golang : How to write CSV data to file
+8.9k Golang : Gorilla web tool kit schema example
+4.8k MariaDB/MySQL : Form select statement or search query with Chinese characters
+22.5k Golang : How to read JPG(JPEG), GIF and PNG files ?
+28k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+17.3k Golang : When to use init() function?