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
+7.8k Golang Hello World Example
+13.8k Golang : unknown escape sequence error
+9.6k Golang : Copy map(hash table) example
+5.3k Python : Delay with time.sleep() function example
+10.1k Golang : Find and replace data in all files recursively
+35.2k Golang : Strip slashes from string example
+8.9k Golang : Inject/embed Javascript before sending out to browser example
+8.3k Golang: Prevent over writing file with md5 hash
+7.8k Golang : Regular Expression find string example
+6.9k Golang : How to solve "too many .rsrc sections" error?
+9.6k Golang : Sort and reverse sort a slice of floats