0.1.11 • Published 11 months ago

qs-to-json v0.1.11

Weekly downloads
17
License
MIT
Repository
github
Last release
11 months ago

Query String to JSON

npm.io Codacy Badge Codacy Badge

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.

  1. 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"
}
  1. 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"]
}
  1. 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

Demo

Contributing

We accept pull requests :D

License

qs-to-json is MIT licensed.

0.1.10

11 months ago

0.1.11

11 months ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.9

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago