0.1.11 • Published 11 months ago
qs-to-json v0.1.11
Query String to JSON
Library to parse given decoded query string and create a JSON object.
Installation
Install qs-to-json using npm
:
npm install --save-dev qs-to-json
Example
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" }
}
Playground
Contributing
We accept pull requests :D
License
qs-to-json is MIT licensed.