I'm currently trying to parse a JSON from a data attribute but I'm getting an error:
Uncaught SyntaxError: Unexpected token � in JSON at position 0
This is my code:
jQuery( document ).ready( function ( $ ) {
let variations = $( "span" ).data( "variations" );
$( JSON.parse( variations ) ).each( function ( index, variation ) {
console.log( variation );
} );
} );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span data-variations='["\ud83d\udc36","\ud83d\udc31"]'></span>
I don't get it. I'm printing the JSON in PHP with this function but I'm stuck in my head here:
<span data-variations='<?= esc_html( json_encode( $variations ) ) ?>'></span>