Library to parse given decoded query string and create a JSON object.
Install qs-to-json using npm
:
npm install --save-dev qs-to-json
NOTE: : qs-to-json currently does not decode the query string. Make sure you pass decoded queryString.
- Convert "&a=1&b=2" to a JSON object:
import queryStringToJSON from "qs-to-json";
const queryString = "&a=1&b=2";
const json = queryStringToJSON(queryString);
console.log(json);
Output would be the following:
{
"a": "1",
"b": "2"
}
- Convert "&a[]=1&a[]=2" to a JSON object:
import queryStringToJSON from "qs-to-json";
const queryString = "&a[]=1&a[]=2";
const json = queryStringToJSON(queryString);
console.log(json);
Output would be the following:
{
"a": ["1", "2"]
}
- Convert "a.name=Nick&b.name=John" to a JSON object:
import queryStringToJSON from "qs-to-json";
const queryString = "a.name=Nick&b.name=John";
const json = queryStringToJSON(queryString);
console.log(json);
Output would be the following:
{
"a": { "name": "Nick" },
"b": { "name": "John" }
}
We accept pull requests :D
qs-to-json is MIT licensed.