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
+5.4k Unix/Linux : How to find out the hard disk size?
+5.3k How to check with curl if my website or the asset is gzipped ?
+19.7k Golang : How to run your code only once with sync.Once object
+6.2k Golang : Selection sort example
+4.8k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+6.9k Golang : Validate credit card example
+21.9k Golang : Repeat a character by multiple of x factor
+21.8k Golang : Match strings by wildcard patterns with filepath.Match() function
+9.9k Golang : How to tokenize source code with text/scanner package?
+8.1k Golang : Oanda bot with Telegram and RSI example
+19k Golang : Execute shell command
+10.6k PHP : Convert(cast) bigInt to string