File tree 3 files changed +71
-0
lines changed
3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ # JSON to HTTP Query string
2
+ > This package allows you to convert JSON to Http query string.
3
+
4
+ ## Getting Started
5
+ To install the module, run the following in the command line:
6
+ ``` bash
7
+ npm i json-to-http-query-string --save
8
+ ```
9
+ Use within your application with the following line of JavaScript:
10
+ ``` js
11
+ const jsonToQuery = require (' json-to-http-query-string' );
12
+ ```
13
+ Example:
14
+ ``` js
15
+ jsonToQuery ({
16
+ foo: " hi" ,
17
+ bar: {
18
+ blah: [1 , 2 , 3 ],
19
+ blah2: 123
20
+ }
21
+ })
22
+ // foo=hi&bar%5Bblah%5D%5B0%5D=1&bar%5Bblah%5D%5B1%5D=2&bar%5Bblah%5D%5B2%5D=3&bar%5Bblah2%5D=123
23
+ ```
Original file line number Diff line number Diff line change
1
+ const jsonToQuery = function ( obj , prefix ) {
2
+ var str = [ ] , p ;
3
+ for ( p in obj ) {
4
+ if ( obj . hasOwnProperty ( p ) ) {
5
+ var k = prefix ? prefix + "[" + p + "]" : p ,
6
+ v = obj [ p ] ;
7
+ str . push (
8
+ v !== null && typeof v === "object"
9
+ ? serialize ( v , k )
10
+ : encodeURIComponent ( k ) + "=" + encodeURIComponent ( v )
11
+ ) ;
12
+ }
13
+ }
14
+ return str . join ( "&" ) ;
15
+ } ;
16
+
17
+ module . exports = jsonToQuery ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " json-to-http-query-string" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " Convert JSON to HTTP Query string" ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1"
8
+ },
9
+ "repository" : {
10
+ "type" : " git" ,
11
+ "url" : " git+https://github.com/SyysBiir/json-to-http-query-string.git"
12
+ },
13
+ "keywords" : [
14
+ " json" ,
15
+ " http" ,
16
+ " request" ,
17
+ " data" ,
18
+ " url" ,
19
+ " website" ,
20
+ " ajax" ,
21
+ " fetch" ,
22
+ " request" ,
23
+ " http"
24
+ ],
25
+ "author" : " Maxim Boyanov" ,
26
+ "license" : " MIT" ,
27
+ "bugs" : {
28
+ "url" : " https://github.com/SyysBiir/json-to-http-query-string/issues"
29
+ },
30
+ "homepage" : " https://github.com/SyysBiir/json-to-http-query-string#readme"
31
+ }
You can’t perform that action at this time.
0 commit comments