 <p>In the string you prepare use:</p> <pre><code>"var fileUploadDic = { 'firstname': 'Jo\\'hn', 'lastname' : 'Macy' , 'country' : 'USA };" </code></pre> <p>Now client side that will look like:</p> <pre><code>var fileUploadDic = { 'firstname': 'Jo\'hn', 'lastname' : 'Macy' , 'country' : 'USA }; </code></pre> <p>If you want to replace <code>''</code> client side you can use <code>[varstr].replace(/''/g,"\\'")</code>, but I think client side will be too late (the Error is already thrown on arrival and interpretation of the sent string)</p>