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
+9.9k Golang : Characters limiter example
+10.4k Golang : Verify Linux user password again before executing a program example
+29.8k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+12.5k Javascript : Prompt confirmation before exit
+14k Golang : Validate hostname
+18.7k Golang : Read directory content with os.Open
+6.9k Swift : Convert (cast) String to Float
+5.2k Golang : Map within a map example
+5.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+5.4k Unix/Linux : Use netstat to find out IP addresses served by your website server
+8.9k Golang : Random Rune generator
+3.6k Chrome : How to block socketloop.com links in Google SERP?