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
+14.3k Golang : Find location by IP address and display with Google Map
+9.4k Golang : How to get quoted string into another string?
+4.1k Golang : Experimental Jawi programming language
+12.4k Golang : Get user input until a command or receive a word to stop
+21.5k Golang : How to read JPG(JPEG), GIF and PNG files ?
+9.7k Swift : Convert (cast) String to Integer
+4.5k Golang : The Tao of importing package
+3.7k Java : Generate multiplication table example
+20.9k Golang : How to reverse slice or array elements order
+7.9k Golang : Executing and evaluating nested loop in html template
+4.8k Linux/Unix/PHP : Restart PHP-FPM
+19.4k Golang : Secure(TLS) connection between server and client