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
+17.7k Golang : Upload/Receive file progress indicator
+3.7k Java : Get FX sentiment from website example
+21.3k Golang : Clean up null characters from input data
+20.3k Golang : How to get own program name during runtime ?
+19.7k Golang : Set or Add HTTP Request Headers
+33.8k Golang : All update packages with go get command
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+11.3k Golang : How to use if, eq and print properly in html template
+5.3k Javascript : Change page title to get viewer attention
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes