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
+8.5k Android Studio : Image button and button example
+20.8k Golang : How to force compile or remove object files first before rebuild?
+14.2k Golang : How to check if your program is running in a terminal
+7k CloudFlare : Another way to get visitor's real IP address
+5.1k Golang : Generate Interleaved 2 inch by 5 inch barcode
+36.2k Golang : Converting a negative number to positive number
+5.9k Golang : Get missing location after unmarshal binary and gob decode time.
+21.7k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+8.8k Golang : automatically figure out array length(size) with three dots
+4.8k Python : Convert(cast) bytes to string example
+10.3k Golang : Resolve domain name to IP4 and IP6 addresses.
+5.6k Javascript : How to replace HTML inside <div>?