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
+7.1k Golang : Process json data with Jason package
+11.7k Golang : Determine if time variables have same calendar day
+9.2k Golang : Extract or copy items from map based on value
+5.7k nginx : force all pages to be SSL
+9.2k Golang : Changing a RGBA image number of channels with OpenCV
+12.7k Golang : Convert(cast) uintptr to string example
+23.6k Golang : Use regular expression to validate domain name
+15.2k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+6.4k Golang : How to validate ISBN?
+5.2k Golang : fmt.Println prints out empty data from struct
+7k Golang : How to iterate a slice without using for loop?
+9k Golang : Generate EAN barcode