SearchParamsParser

Parsing a query string into a nested object.

SearchParamsParser is the default ParsersRegistry.searchParamsParser. It fills Context.search, and BodyParser also routes application/x-www-form-urlencoded bodies through it, so a query string and a form post with matching field names produce the same shape.

Contents
  1. SearchParamsParser

SearchParamsParser

class

class SearchParamsParser extends ParserBase<URLSearchParams>

Turns URLSearchParams into a nested object.

Keys are read as paths through ParserBase.parseKey, so ?filter[status]=open&tags[0]=a builds the objects and arrays it describes. Repeated keys collect into an array, which is how ?tag=a&tag=b arrives without any bracket notation.

Values are coerced through ParserBase.tryParseJSON, so ?page=2 and ?active=true arrive as a number and a boolean rather than as strings.

SearchParamsParser.parse()

parse(searchParams: URLSearchParams): Record<string, unknown>

Parses a query string into a nested object.

Parameters

Returns — The nested object, built on a null prototype by createSafeObject so a __proto__ key in the query string cannot reach Object.prototype.