<p>I need to <a href="https://en.wikipedia.org/wiki/Serialization" rel="noreferrer">serialize</a> an object to <a href="https://www.json.org/" rel="noreferrer">JSON</a>. I'm using <a href="https://api.jquery.com/" rel="noreferrer">jQuery</a>. Is there a "standard" way to do this?</p>

<p>My specific situation: I have an array defined as shown below:</p>

<pre><code>var countries = new Array();
countries[0] = 'ga';
countries[1] = 'cd';
...
</code></pre>

<p>and I need to turn this into a string to pass to <a href="https://www.w3schools.com/jquery/ajax_ajax.asp" rel="noreferrer"><code>$.ajax()</code></a> like this:</p>

<pre><code>$.ajax({
    type: "POST",
    url: "Concessions.aspx/GetConcessions",
    data: "{'countries':['ga','cd']}",
...
</code></pre>

I haven't used it but you might want to try the
jQuery plugin written by Mark Gibson
It adds the two functions:
```
$.toJSON(value)
```
,
```
$.parseJSON(json_str, [safe])
```
.