There is a problem with the string you are calling a json. I have made some changes to it below. If you properly format the string to a correct json, the code below works.
$str = '{
"action" : "create",
"record": {
"type": "n$product",
"fields": {
"nname": "Bread",
"nprice": 2.11
},
"namespaces": { "my.demo": "n" }
}
}';
$response = json_decode($str, TRUE);
echo '<br> action' . $response["action"] . '<br><br>';