Why aren't REST (JSON) responses using Content-Type: application/json?

6717
5
07-01-2010 09:18 AM
EricWilliams
New Contributor
Working with the REST API and I noticed that the content-types are not being set correctly.

As an example:
ESRI_Census_USA Sample Service:
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer?f=...

returns:
Content-Type:text/plain;

Is there configuration or URL parameter to fix this?
0 Kudos
5 Replies
RahulRavikumar
New Contributor
REST (JSON) responses are set to 'text/plain' rather than 'application/json' for a couple of reasons.

a. 'text/plain' is friendlier.
If we used Content-Type = 'application/json', it is not displayed by the browser. The browser forces you to download and save the response, before allowing you to view it. This would not happen if we used 'text/plain'.

b. The ArcGIS Server REST API supports JavaScript callbacks ('callback' parameter) which help us get around the cross domain issues. When JSON is wrapped by a callback, it is no longer JSON in the 'strict' sense.

Therefore we chose to use 'text/plain' rather than 'application/json'

If you absolutely want 'application/json' as the content-type, you can use a proxy that overrides the headers for the JSON requests, and make calls to the REST API using your proxy.
0 Kudos
PetrDiviš
New Contributor III

Hello,

I think after 7 years of suffering with text\plain, Esri could finally accept the standard What is the correct JSON content type? - Stack Overflow 

also when setting the content type in SOE and then calling the request with f=json i always get invalid text\plain instead of my application\json.

So pretty please with sugar on top, fix the bug

Petr

MarcGraham1
Occasional Contributor

Old thread, but for anyone else googling this... At 10.6 the default is application/json:

Server Properties—ArcGIS REST API: Administer your server | ArcGIS for Developers 

tldr:  "defaultJsonResponseContentType—At 10.6, the default content-type for JSON and JSON with callback responses has been changed from text/plain to application/json and application/javascript, respectively. "

LeonAus
New Contributor III

Marc,

My ArcGIS server install is 10.6.1 and this change doesn't seem to be working. By default I still get text/plain when requesting a json response. I tried to add "defaultJsonResponseContentType": "application/json" into my system properties as a long shot but that didn't make a difference.

Is there anything else that is needed to get the response in application/json or is this a bug and I should log it with my local distributor?

0 Kudos
LeonAus
New Contributor III

False alarm. The rest directory automatically uses f=pjson as the format which returns text/plain. Changed to f=json returns the application/json needed.

0 Kudos