{"id":3761,"date":"2011-05-04T12:16:45","date_gmt":"2011-05-04T06:46:45","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=3761"},"modified":"2022-01-12T19:03:44","modified_gmt":"2022-01-12T13:33:44","slug":"jquery-create-url-query-string-from-jsonarray","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/jquery-create-url-query-string-from-jsonarray\/","title":{"rendered":"JQuery : create URL query string from JSON\/Array"},"content":{"rendered":"<p>Hi Friends,<\/p>\n<p>I was <a title=\"Javascript development services\" href=\"http:\/\/www.tothenew.com\/front-end-angularjs-development\">writing javascript<\/a> to reload my page with different parameters. So I needed to create the queryString of those parameters but I didn&#8217;t want to create it of my own. I already knew about <a href=\"http:\/\/api.jquery.com\/serialize\/\">jQuery.serialize()<\/a> which serializes the form and creates the queryString, but unfortunately I didn&#8217;t have form. So that gave me opportunity to learn about new <a href=\"http:\/\/api.jquery.com\/jQuery.param\/\">jQuery.param()<\/a> which converts the JSON\/Array into query string. Let us look at few examples below :<\/p>\n<p>[js]<br \/>\nvar myParams = {country:&quot;US&quot;, customerId:&quot;1&quot;}<br \/>\njQuery.param(myParams);<\/p>\n<p>Output: &quot;country=US&amp;customerId=1&quot;<br \/>\n[\/js]<\/p>\n<p>&nbsp;<\/p>\n<p>[js]<br \/>\nvar myParams = {name: &quot;Amit Jain&quot;,days:[&#8216;Mon&#8217;,&#8217;Tue&#8217;,&#8217;Sat&#8217;] };<br \/>\njQuery.param(myParams);<\/p>\n<p>Output: &quot;name=Amit+Jain&amp;days%5B%5D=Mon&amp;days%5B%5D=Tue&amp;days%5B%5D=Sat&quot;<br \/>\n[\/js]<\/p>\n<p>&nbsp;<\/p>\n<p>[js]<br \/>\nvar myParams = {name: &quot;Diana&quot;,address:{<br \/>\n  line1:&quot;232 Alder Dr.&quot;,<br \/>\n  line2:&quot;Alder City&quot;,<br \/>\n  state : &quot;Utah&quot;,<br \/>\n  country: &quot;US&quot;<br \/>\n}};<br \/>\njQuery.param(myParams);<\/p>\n<p>Output : &quot;name=Diana&amp;address%5Bline1%5D=232+Alder+Dr.&amp;address%5Bline2%5D=Alder+City&amp;address%5Bstate%5D=Utah&amp;address%5Bcountry%5D=US&quot;<br \/>\n[\/js]<\/p>\n<p>Hope this helped!<\/p>\n<p>Contact our <a title=\"Grails Developers\" href=\"http:\/\/www.tothenew.com\/grails-application-development\">Grails developers team<\/a> for your queries.<br \/>\n<!--more--><br \/>\nCheers!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi Friends, I was writing javascript to reload my page with different parameters. So I needed to create the queryString of those parameters but I didn&#8217;t want to create it of my own. I already knew about jQuery.serialize() which serializes the form and creates the queryString, but unfortunately I didn&#8217;t have form. So that gave [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":72},"categories":[1],"tags":[27,49,570,571],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3761"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=3761"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3761\/revisions"}],"predecessor-version":[{"id":54614,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3761\/revisions\/54614"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=3761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=3761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=3761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}