qs
Query string parser and serializer for JavaScript with nested objects, arrays, and depth-limited safe defaults.
Official Documentation ↗v6. Check the official docs for the latest API surface.Installation
npm install qspnpm add qsMethods
No methods match this filter.
Query string parser and serializer for JavaScript with nested objects, arrays, and depth-limited safe defaults.
Overview
qs is the query string engine behind Express body and query parsing. Beyond flat pairs it round-trips nested objects and arrays, supports several array encodings, and can serialize complex filter trees into a URL.
Parsing is deliberately defensive: depth, arrayLimit, and parameterLimit cap what a crafted URL can build, and prototype-poisoning keys are neutralized. Those defaults, along with ignoreQueryPrefix and comma formats, make qs suitable for both building requests and decoding user-controlled URLs.
Core Methods
The most frequently used entry points, with signatures and runnable examples:
qs.stringify— Serializes objects into query strings; nested objects become bracket notation and arrays follow arrayFormat.qs.parse— Parses a query string back into nested objects and arrays, ignoring the leading question mark when asked.depth / plainObjects— Bounds how deeply bracket keys nest and how many pairs parse, protecting parsers from crafted inputs.
Usage Notes
- Pin one arrayFormat per system and use it on both stringify and parse sides to keep URLs stable.
- Validate parsed structures with a schema before use; qs gives shape, not types or semantics.
- Use allowDots consistently if your API style prefers user.name over user[name].
Common Pitfalls
- URLSearchParams and qs produce different array encodings; mixing them across client and server breaks round-trips.
- Excessively raising depth or parameterLimit to satisfy one partner reopens resource-exhaustion risk for every route.
- Values are always strings after parsing; cast explicitly instead of relying on loose equality.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/ljharb/qs@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:05.265Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- The strictDepth option adds a layer of protection by throwing an error when the limit is exceeded, allowing you to catch and handle such cases. (https://cdn.jsdelivr.net/gh/ljharb/qs@latest/README.md)
- This option will generate a descriptive error if the query string exceeds a configured limit. (https://cdn.jsdelivr.net/gh/ljharb/qs@latest/README.md)
- With the default throwOnLimitExceeded: false, exceeding arrayLimit never rejects or truncates input; it only changes the container type, and the resulting object still holds every element (so its size stays proportional to the input). (https://cdn.jsdelivr.net/gh/ljharb/qs@latest/README.md)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/ljharb/qs@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:05.265Z.
- If you need a hard limit that rejects oversized arrays in untrusted query strings, set throwOnLimitExceeded: true. (https://cdn.jsdelivr.net/gh/ljharb/qs@latest/README.md)
FAQ
- Why do brackets appear in my query string?
- The default arrayFormat is indices, encoding arrays as tags[0]=a&tags[1]=b, and nested objects as user[name]=ada. Switch arrayFormat to brackets, comma, or repeat to match whatever the receiving API expects.
- How does qs protect against prototype pollution?
- Keys such as __proto__ and constructor are dropped or handled without mutating Object.prototype, and depth plus parameterLimit bound how much structure an input can create. Keep those defaults unless a partner format forces otherwise.
- When should I use allowDots?
- Dotted notation, user.name=ada, is common in some API styles. allowDots: true makes both stringify and parse use it, but pick one convention per system to avoid producing both bracket and dot forms for the same object.
Report a problem with this API docOpens a pre-filled issue on GitHub.