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
+15k Golang : Basic authentication with .htpasswd file
+11.8k Golang : Find age or leap age from date of birth example
+19.7k Golang : Close channel after ticker stopped example
+28.8k Get file path of temporary file in Go
+5.7k Python : Print unicode escape characters and string
+29.6k Golang : How to create new XML file ?
+12k Golang : How to parse plain email text and process email header?
+17.2k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+10.3k Golang : Text file editor (accept input from screen and save to file)
+23.7k Golang : Read a file into an array or slice example
+7.4k Golang : Not able to grep log.Println() output
+12.7k Golang : Transform comma separated string to slice example