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
+8.4k Golang : ffmpeg with os/exec.Command() returns non-zero status
+17.1k Golang : Logging with logrus
+4.2k Python : Create Whois client or function example
+14.9k Golang : Read integer from file into array
+4.5k Golang : Display advertisement images or strings on random order
+6.3k Golang : File system scanning
+3.8k Linux/MacOSX : How to symlink a file?
+16.1k Golang : Qt image viewer example
+8.2k Golang : Detect number of active displays and the display's resolution
+9.4k Golang : Simple File Server
+7.6k Android Studio : Indicate progression with ProgressBar example