I've never tried to do something like this but I think that you're having issue because json_encode returns a json encoded string. You then need to decode this string on the javascript side of things. Try something like the following:
var myJson = JSON.parse();
console.log(myJson);