<?php
$str = 'This is "some" {"text" : \'duudu\', \'duuue\' : "yey" } "and" {"some", "other"} "text"';
}, $str) . "\n";
echo "opt2: " . preg_replace('~[\'"](?!(?:[^{}]*{[^{}]*})*[^{}]*$)~', '\"' , $str) . "\n" ?>
PD9waHAKJHN0ciA9ICdUaGlzIGlzICJzb21lIiB7InRleHQiIDogXCdkdXVkdVwnLCBcJ2R1dXVlXCcgOiAieWV5IiB9ICJhbmQiIHsic29tZSIsICJvdGhlciJ9ICJ0ZXh0Iic7CmVjaG8gIm9wdDE6ICIgLiBwcmVnX3JlcGxhY2VfY2FsbGJhY2soJ34oe1tefV0qfSl+JywgZnVuY3Rpb24oJG0pIHsKICAgICAgIHJldHVybiBwcmVnX3JlcGxhY2UoJ34oPzwhXFxcXClbXCciXX4nLCAnXCInLCAkbVsxXSk7CiAgICB9LCAkc3RyKSAuICJcbiI7CiAgICAKCmVjaG8gIm9wdDI6ICIgLiBwcmVnX3JlcGxhY2UoJ35bXCciXSg/ISg/Oltee31dKntbXnt9XSp9KSpbXnt9XSokKX4nLCAnXCInICwgJHN0cikgLiAiXG4iCj8+