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

Recommended Answers

All 8 Replies

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

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.

Hello Troy.

Believe me when I say it does! ;)

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

I think problem is in code editor

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

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

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 :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.