id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc,focuses 47834,Allow un-encoded output / other content types,lkf_tanzt,,"== The issue I want to use the REST-API to provide other content types than JSON. It’s possible to set the HTTP header `Content-Type` to other values but the data in the the response are always json encoded so they are wrapped in """" in the result echoed. The content type is ignored here. I followed the program flow to this line: https://core.trac.wordpress.org/browser/branches/5.2/src/wp-includes/rest-api/class-wp-rest-server.php?rev=45281#L404 The `$result` is always json encoded, regardless of how the Content-type header was set. ---- So what would be a possible solution? == 1. Check for content-type header One solution would be to query the header flied `Content-Type` from `$result` (the headers are already sent in line 361) and encode the content only if the header is set to `application/json` or a subtype of this. So the data are not encoded, if the content-type header is manually set for a response to something else, and those other content-types would work well. By default the content-type is set to `application/json` and the data is encoded, so everything would work as before. == 2. Introduce filterable encode switch We could introduce a flag {{{$do_json_encode}}} which would allow to skip the encoding part by adding a filter on this and returning false. A similar thing is done in [https://core.trac.wordpress.org/browser/branches/5.2/src/wp-includes/rest-api/class-wp-rest-server.php?rev=45281#L380 Line 380] with `$served`. So this could look like the following: {{{#!php $do_json_encode = apply_filters( 'rest_do_json_encode', true, $result, $request, $this ); if ( $do_json_encode ){ // the currently existing line $result = wp_json_encode( $result ); } }}} Since the value defaults to `true` the default behaviour would not change but we would introduce the option to alter this with a filter and since we provide `$result` and `$request` the user/developer can decide on his own if he want’s to encode the data or not.",enhancement,closed,normal,,REST API,5.2.2,normal,maybelater,has-patch reporter-feedback,,rest-api