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.3k How to enable MariaDB/MySQL logs ?
+4.8k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+9.1k Golang : Find the length of big.Int variable example
+6.6k Fix sudo yum hang problem with no output or error messages
+5.7k Golang : Use NLP to get sentences for each paragraph example
+36k Golang : Validate IP address
+9.4k Javascript : Read/parse JSON data from HTTP response
+26.5k Golang : Find files by extension
+10.7k Golang : How to transmit update file to client by HTTP request example
+8.8k Golang : Get curl -I or head data from URL example
+4.9k Python : Create Whois client or function example