utf8 encoding in json rest api

The problem is here:

'excerpt' => wp_json_encode($post->post_excerpt), 

That array will get passed through wp_json_encode by the REST API, so it gets double encoded, so remove the wp_json_encode here, and it’ll work out fine, it’s just encoding, it’s not the literal human readable value.

E.g. put it in your browsers dev console and output the result, and you’ll see it’s a non-issue:

enter image description here

As you can see, was encoded as \u2019O because 20190 is the unicode character code of , and HTML can’t natively use those characters without some form of encoding. That’s why when you inspect HTML, you’ll see & but when you view it in the browser you see &, the same thing is happening here

Leave a Comment