Title: Breaks JSON/REST-API Output
Last modified: March 2, 2017

---

# Breaks JSON/REST-API Output

 *  [ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/)
 * WP Fastest Cache adds String “<!– html is corrupted –>” to end of JSON/REST-API
   output of WordPress which leads to invalid JSON.
 * Examples:
    - hXXp://www.wpfastestcache.com/wp-json/wp/v2/posts
    - hXXp://www.wpfastestcache.com/wp-json/wp/v2/users
 * Please fix soon, thanks.
    -  This topic was modified 9 years, 3 months ago by [ov3rfly](https://wordpress.org/support/users/ov3rfly/).

Viewing 15 replies - 16 through 30 (of 31 total)

[←](https://wordpress.org/support/topic/breaks-json-api-output/?output_format=md)
[1](https://wordpress.org/support/topic/breaks-json-api-output/?output_format=md)
2 [3](https://wordpress.org/support/topic/breaks-json-api-output/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/breaks-json-api-output/page/3/?output_format=md)

 *  Thread Starter [ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8872338)
 * No need to detect json pages or similar. Start thinking the other way round, 
   only add HTML-comments if you know it is HTML-data. Problem solved.
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8872355)
 * > WP Fastest Cache adds String “<!– html is corrupted –>” to end of JSON/REST-
   > API output of WordPress which leads to invalid JSON.
   > Examples:
   > hXXp://www.wpfastestcache.com/wp-json/wp/v2/posts
   >  hXXp://www.wpfastestcache.
   > com/wp-json/wp/v2/users Please fix soon, thanks.
 * I have fixed it few minutes ago but I did not release a new version. You should
   download the following version.
 * [https://downloads.wordpress.org/plugin/wp-fastest-cache.zip](https://downloads.wordpress.org/plugin/wp-fastest-cache.zip)
 *  Thread Starter [ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8872384)
 * Testcases on your server still have `<!– html is corrupted –>` added.
 * Downloaded .zip says 0.8.6.6 in header and still has this code in `../inc/cache.
   php` which obviously will print the comment to anything which does not have an`
   html` and `body` tag.
 *     ```
       }else if($this->checkHtml($buffer)){
       	return $buffer."<!-- html is corrupted -->";
       }else
       ```
   
 * Let me know if a [real fix as described above](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8872338)
   is ready, take your time, as described this can not be solved by comparing some
   strings in URLs.
 * Thanks for the quick feedback.
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8873592)
 * I have added the following code.
 * >  if(preg_match(“/^\/wp-json/”, $_SERVER[“REQUEST_URI”])){
   >  return true; }
 *  Thread Starter [ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8873610)
 * As explained, that’s not a real fix, just a quick hack workaround which does 
   not cover all kind of other endpoints which deliver JSON or similar.
 * Start thinking the other way round, only add HTML-comments if you know it is 
   HTML-data. Problem solved.
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8873617)
 * You are %100 right but I cannot detect that the page is html or json. You should
   get and use the temp solution.
 *  Thread Starter [ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8873645)
 * As explained, if you cannot detect html or json, **do not add** HTML-comments.
 * Minimum fix:
 *     ```
       }else if($this->checkHtml($buffer)){
       	return $buffer;
       }else
       ```
   
 * Minimum fix with debug info:
 *     ```
       }else if($this->checkHtml($buffer)){
       	if ( WP_DEBUG ) error_log( 'WPFC: <!– html is corrupted –>' );
       	return $buffer;
       }else
       ```
   
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8873651)
 * ok, you are right.
 *  [SongofHannah](https://wordpress.org/support/users/songofhannah/)
 * (@songofhannah)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8890335)
 * Is this fixed yet?
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8900338)
 * Hi [@songofhannah](https://wordpress.org/support/users/songofhannah/), The urls
   which start with /wp-json/ are not cached with the following version.
 * [https://downloads.wordpress.org/plugin/wp-fastest-cache.zip](https://downloads.wordpress.org/plugin/wp-fastest-cache.zip)
 *  [SongofHannah](https://wordpress.org/support/users/songofhannah/)
 * (@songofhannah)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8907647)
 * The URL above looks to be the WP latest version. So all I need to do it update,
   right?
 *  Thread Starter [ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8907701)
 * The code in 0.8.6.7 still adds HTML-comments to any non-HTML data.
 * Please add a real fix as described above.
 * Excluding certain URLs from cache just hides the problem and actually also defeats
   the purpose of a cache plugin.
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8907881)
 * > The URL above looks to be the WP latest version. So all I need to do it update,
   > right?
 * yes.
 * > The code in 0.8.6.7 still adds HTML-comments to any non-HTML data.
   > Please add a real fix as described above.
   > Excluding certain URLs from cache just hides the problem and actually also 
   > defeats the purpose of a cache plugin.
 * Please contact me via email: [http://www.wpfastestcache.com/contact-us/](http://www.wpfastestcache.com/contact-us/)
 *  Thread Starter [ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8908077)
 * > The code in 0.8.6.7 still adds HTML-comments to any non-HTML data.
 * This bug still affects any custom WordPress endpoints.
 * How to reproduce? Create an own endpoint.
 * Find a [full example as plugin here](https://webdevstudios.com/2015/07/09/creating-simple-json-endpoint-wordpress/),
   link to github gist at end of article.
 * With above plugin, add a “GIFs” item with a tag `sdf`
 * Open link to endpoint in browser: `http://example.com/gifs/sdf/`
 * Get corrupted JSON:
 * `[{"link":"http:\/\/example.com\/wp-content\/uploads\/2017\/01\/example.jpg","
   title":"test"}]<!-- html is corrupted -->`
 * Another Link with non-existing GIF-tag: `http://example.com/gifs/yxcvb/`
 * `[]<!-- html is corrupted -->`
 * No need to contact you via email, there is enough information above already.
 * The real fix: Only add HTML-comments if you know it is HTML-data. If you can’t
   detect page format, **do not add anything** at all. Problem solved.
 *  Plugin Author [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * (@emrevona)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/2/#post-8908141)
 * [@ov3rfly](https://wordpress.org/support/users/ov3rfly/), please contact me via
   email and I will fix it.
 * [http://www.wpfastestcache.com/contact-us/](http://www.wpfastestcache.com/contact-us/)

Viewing 15 replies - 16 through 30 (of 31 total)

[←](https://wordpress.org/support/topic/breaks-json-api-output/?output_format=md)
[1](https://wordpress.org/support/topic/breaks-json-api-output/?output_format=md)
2 [3](https://wordpress.org/support/topic/breaks-json-api-output/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/breaks-json-api-output/page/3/?output_format=md)

The topic ‘Breaks JSON/REST-API Output’ is closed to new replies.

 * ![](https://ps.w.org/wp-fastest-cache/assets/icon-256x256.png?rev=2064586)
 * [WP Fastest Cache - WordPress Cache Plugin](https://wordpress.org/plugins/wp-fastest-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-fastest-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-fastest-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-fastest-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-fastest-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-fastest-cache/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [corrupt](https://wordpress.org/support/topic-tag/corrupt/)
 * [json](https://wordpress.org/support/topic-tag/json/)
 * [rest](https://wordpress.org/support/topic-tag/rest/)

 * 31 replies
 * 3 participants
 * Last reply from: [Emre Vona](https://wordpress.org/support/users/emrevona/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/breaks-json-api-output/page/3/#post-8909733)
 * Status: not resolved