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
+24.7k Golang : Create PDF file from HTML file
+8.2k PHP : How to parse ElasticSearch JSON ?
+24.2k Golang : Change file read or write permission example
+15k nginx: [emerg] unknown directive "ssl"
+5.2k Golang : What is StructTag and how to get StructTag's value?
+23.3k Find and replace a character in a string in Go
+13.4k Golang : Tutorial on loading GOB and PEM files
+13.3k Golang : reCAPTCHA example
+7.2k Golang : Convert source code to assembly language
+10.9k CodeIgniter : How to check if a session exist in PHP?
+5.5k Golang : Error handling methods
+13.7k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example