FormDataParser

Parsing multipart/form-data into a nested object.

FormDataParser is the default ParsersRegistry.formDataParser, reached through BodyParser rather than called directly. It applies the same bracket-notation nesting as SearchParamsParser, so a form post and a query string with matching field names produce the same shape — the difference is that a form can also carry files, which are kept as File objects instead of being coerced.

Contents
  1. FormDataParser

FormDataParser

class

class FormDataParser extends ParserBase<FormData>

Turns a FormData into a nested object.

Field names are read as paths through ParserBase.parseKey, so user[address][city] and tags[0] build the objects and arrays they describe. Repeated names collect into an array, which is how a multi-select or a multi-file input arrives without any bracket notation at all.

Values are coerced through ParserBase.tryParseJSON, so "true" and "42" arrive as a boolean and a number rather than as strings. Files are exempt — a File is passed through untouched.

FormDataParser.parse()

parse(formData: FormData): Record<string, unknown>

Parses form data into a nested object.

Parameters

Returns — The nested object, built on a null prototype by createSafeObject so a __proto__ field name cannot reach Object.prototype.