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
+4.6k PHP : Convert CSV to JSON with YQL example
+23.9k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+12.6k Javascript : Prompt confirmation before exit
+13.9k Golang : How to get Unix file descriptor for console and file
+11.6k Golang : Pass database connection to function called from another package and HTTP Handler
+8.9k Golang : Compare files modify date example
+5.5k Golang : Find the longest line of text example
+4.5k Golang : Display advertisement images or strings on random order
+5.7k Golang : Muxing with Martini example
+4.6k Unix/Linux/MacOSx : Get local IP address
+6.8k Golang : Sort words with first uppercase letter
+10.2k Golang : Post data with url.Values{}