Passing variable to object not working

Now that I am able to access properties in json format, <“y:id”>, I now have another issue. Im trying to access a value in json like so:

$code = $json_result->item->{"y:code"}->embedcode;

The above code works, it gives me the value just fine. But instead of manually setting the path Im trying to do it dynamically with a variable like so:

$codevariable = '{"y:code"}';
$code = $json_result->item->$codevariable->embedcode;

When I do that I get a blank value, just doesnt work. Can anyone help me on this? Thanks!

the curly braces are a control character, not part of the string itself.
Try $codevariable = “y:code”;