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
+15k Golang : Submit web forms without browser by http.PostForm example
+11.3k Google Maps URL parameters configuration
+7.5k Golang : How to convert strange string to JSON with json.MarshalIndent
+7k Golang : Pat multiplexer routing example
+7.6k Golang : Detect sample rate, channels or latency with PortAudio
+7.1k Nginx : Password protect a directory/folder
+6.2k Golang : Create new color from command line parameters
+10.4k Golang : Bcrypting password
+10.3k Golang : Check a web page existence with HEAD request example
+8.4k Golang : Add build version and other information in executables
+22.5k Golang : Convert seconds to minutes and remainder seconds
+5.4k PHP : Hide PHP version information from curl