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.7k Golang : Read input from console line
+6k Golang : Mapping Iban to Dunging alphabets
+25.8k Golang : Convert CSV data to JSON format and save to file
+5.9k Golang : Calculate BMI and risk category
+4.6k Linux/Unix/PHP : Restart PHP-FPM
+9.5k Golang : Get UDP client IP address and differentiate clients by port number
+18.3k Golang : Count JSON objects and convert to slice/array
+10.3k Golang : Display a text file line by line with line number example
+10k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+5.8k Mac OSX : Find large files by size
+13.1k Golang : Find network of an IP address