qs is a robust JavaScript library for parsing and stringifying URL query strings, with comprehensive support for nesting objects and arrays. It is currently on version 6.15.1 and maintains a steady release cadence with a focus on stability and security patches. Key differentiators include its configurable depth limits for parsing, the ability to handle URI-encoded strings, and built-in protections against prototype pollution through options like `plainObjects` and `allowPrototypes` (which is dangerous if enabled). Unlike the native `querystring` module in Node.js, `qs` offers more advanced features like array indexing and custom parsing/stringifying logic, making it suitable for complex data structures often found in web applications.
npm install qsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic `qs.parse` and `qs.stringify` functionality, including nested objects, arrays, and the default depth limit behavior.
If nested object parsing via dots is desired, set `qs.parse(str, { allowDots: false })`. If you were relying on `{ 'a.b': 'c' }` behavior and upgraded from v5, ensure your code handles the new default.Always explicitly set `arrayLimit` in `qs.parse(str, { arrayLimit: <your_desired_limit> })` if you expect arrays with a variable or large number of elements to prevent unexpected truncation.For deeply nested structures, provide a higher `depth` option to `qs.parse(string, { depth: <max_depth> })`. Consider also using `strictDepth: true` to throw an error instead of truncating, making unexpected depth explicit.NEVER set `allowPrototypes: true` with untrusted user input. By default, `qs` prevents this. If you need to handle keys like `__proto__`, `constructor`, or `prototype` as actual data keys, use `plainObjects: true` to return a null-prototype object (`Object.create(null)`), which isolates the parsed data from the global `Object.prototype`.
For CommonJS, use `const qs = require('qs'); const obj = qs.parse('...');`. For ESM, use `import qs from 'qs'; const obj = qs.parse('...');`.Either increase the `depth` option to accommodate the expected nesting level (`qs.parse(str, { depth: <new_depth> })`) or adjust the input to reduce nesting. If truncation is acceptable, remove `strictDepth: true`.To parse `a.b=c` into `{ a: { b: 'c' } }`, use `qs.parse(str, { allowDots: false })`. To handle deep nesting, adjust the `depth` option (e.g., `qs.parse(str, { depth: 10 })`).No dependency data recorded yet.