0

Hello

I'm trying to generate a JSON file with the JSON.Stringify, but, the quotes that are generated by my code o are not compliant with the json format. It's generating smart quotes to the left like (“object”:“pair”) instead of ("object":"pair")

Does anybody knows how to solve this? I've searched dozens of articles but none was clear or worked

So far I've tried this pieces of code

//myObject is a string

myObject = myObject.replace('”','\u0022');
myObject = myObject.replace('“','\u0022');

myObject = myObject.replace('”','\"');
myObject = myObject.replace('“','\"');


myObject = myObject.replace('”','"');
myObject = myObject.replace('“','"');

myObject = myObject.replace('\u201C', '\u0022');
myObject = myObject.replace('\u201D', '\u0022');

But none seems to work

Glad for all the help I can have on this

4
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by fantasma
0

I don't know much about JSON format, but the replace method only works once, and you need to repeat it in order to replace all (google it).

Example:

<script type="text/javascript">

var str="Visit Microsoft! Microsoft";
document.write(str.replace("Microsoft","W3Schools"));

</script>

Returns:

Visit W3Schools! Microsoft 

So only the first one is replaced (curtisy of w3schools, I was too lazy to fire up editor)

~G

0

Hello

I'm trying to generate a JSON file with the JSON.Stringify, but, the quotes that are generated by my code o are not compliant with the json format. It's generating smart quotes to the left like (“object”:“pair”) instead of ("object":"pair")

Does anybody knows how to solve this? I've searched dozens of articles but none was clear or worked

That's not possible, json doesn't do smart quoting.

0

Graphics, with those replacement arguments, not even the first line is replaced!! :(

0

So what should I do?

I've already changed the code editor to UTF-8 but the problem still persists

Note: This isn't a webpage code, but an Adobe InDesign script I've coded

0

I generally use standard editor like notepad/ wordpad
1) copy whole code
2) copy that start quote smart character
3) open find /replace utitlity
4) paste that charcter in find
5) type quote charter in replace
6) click replace all
7) repeat 1-6 for end quote smart character

0

Thank you for your reply

That generaly works, but, the file is generated by the InDesign, and I would want a more direct generation, without having the trouble of replacing the quotes manually .

I don't know, but the quotes are "static" in the script, the ones which come with the generated text are escaped, and don't really matter for the "equation".

Unfortunately, the "no simple solution" idea persists :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.