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
+12k Golang : Date and Time formatting
+4.9k Golang : Generate multiplication table from an integer example
+8.4k Golang : ffmpeg with os/exec.Command() returns non-zero status
+19.7k Curl usage examples with Golang
+17.2k Golang : Write file with io.WriteString
+38.1k Golang : UDP client server read write example
+23.9k Golang : Convert uint value to string type
+5.6k Golang : Gargish-English language translator
+8.2k Golang : How to get garbage collection data?
+17.7k Golang : Read input from console line
+17.4k Unmarshal/Load CSV record into struct in Go
+7.1k Golang : HTTP Server Example