Query String Parser

Convert URL’s query string into JavaScript object.

Example

Input

Output

Please visit one of the links above!

Usage

q2o(query, eval = true);
<script src="q2o.min.js"></script>
<script>
var config = q2o('?foo=1&bar=2');

console.log(config); // {"foo":1,"bar":2}
console.log(config.foo); // 1
console.log(config.bar); // 2
</script>

Object Serializer

A function called o2q, to convert object into URL’s query string is available here.

Usage

o2q(object, separator = '&', deep = 1, include_false = false);
<script src="o2q.min.js"></script>
<script>
var data = {
        a: 'b',
        c: 'd',
        e: {
            f: 'g',
            h: 'i',
            j: {
                k: 'l',
                m: 'n'
            }
        }
    },
    set_1 = o2q(data),
    set_2 = o2q(data, '&', 2);

console.log(set_1); // ?a=b&c=d&e[f]=g&e[h]=i&e[j]={"k":"l","m":"n"}
console.log(set_2); // ?a=b&c=d&e[f]=g&e[h]=i&e[j][k]=l&e[j][m]=n
</script>