I have a InDesign script that converts a page into JSON format.
However this comes with smart “curly” double quotes instead of the normal ones (” “). Of course this produces an invalid JSON file.
Trying to solve the problem, as I needed to do some other operations with PHP on these files, I’ve tryied to embrace this problem and solve it on the file upload.
Turns out, that the function only works (not allways) on quotes produced by InDesign in a Windows PC. If you run the script on MAC, and upload the file, it won’t work at all because the encoding seems to be different. I’ve tried other solutions that this one, but, they wouldn’t produce any result at all.
Here’s the script.
function quoteReplacer($file)
{
$string = file_get_contents($file);
$string = to_utf8($string);
$bits = array('\xe2\x80\x9c', '\xe2\x80\x9d', '\xe2\x80\x98', '\xe2\x80\x99','â','â');
$string = str_replace($bits,'"',$string);
file_put_contents($file,$string);
//file_put_contents($file,$string);
}
function to_utf8( $string ) {
return iconv( 'CP1250', 'UTF-8', $string);
}
This script should work:
To replace all the strange characters that could clog up your JSON.
courtesy: link.
Alternatively you could have them turn it off on all workstations by pressing Command + Shift + Option + the quote key next to Enter for MAC, the equivalent on pc is probably ctrl + alt + shift + ' or you can find it in preferences.