× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Let JSON.stringify() do the dirty work

James Jensen
Dec 13, 2014
<p>Remember that JSON was literally created to represent JavaScript objects. If you're trying to build a JSON string, the absolute easiest way is to build a plain old JSON object and call `JSON.stringify()` on it.</p><pre><code class="language-javascript">// instead of: var s = "{\"name\":\"...\",\"children\":[{\"name\":\"...\"}]}"; // use var obj = {name: "...", children: [{name: "..."}]}; var s = JSON.stringify(obj);</code></pre><p> </p>
comments powered by Disqus