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
+6.5k Golang : Selection sort example
+10.4k Golang : Random Rune generator
+8k Swift : Convert (cast) String to Double
+29.3k Golang : Get first few and last few characters from string
+16k Golang : Read a file line by line
+6.1k Unix/Linux : How to open tar.gz file ?
+19.3k Mac OSX : Homebrew and Golang
+18.8k Golang : Send email with attachment
+14k Golang : Qt progress dialog example
+14.1k Golang : Get current time
+6.5k Golang : Calculate US Dollar Index (DXY)
+31.1k Golang : Interpolating or substituting variables in string examples