Minimal query string encoding, supporting nested objects
npm install query-string-encode




Similar to jQuery's $.param and qs.stringify()
npm i query-string-encode
oryarn add query-string-encode
js
const queryStringEncode = require('query-string-encode');
queryStringEncode({hello: 'world'})
``js
// Using with Fetch API
fetch('/comment', {
method: 'post',
headers: new Headers({'content-type': 'application/x-www-form-urlencoded'}),
body: queryStringEncode({userId: 1, comment: 'Hello'})
});
`Beware
Unlike serialized JSON, query strings are lossy. The only supported data type is string, so it's not possible to distinguishing between "true" vs true or 5 vs "5" or ["a"] vs {0:'a'}`. Using JSON is safer. This is an inherent problem with the format and applies to any query string serializer.