Toolbox-XToolbox-X

Create FormData

Converts JavaScript objects, nested structures, and files into standard FormData with comprehensive formatting options.

createFormData

Converts JavaScript objects into FormData with extensive configuration options for handling nested structures, files, and case transformations.

Function Signature

function createFormData<T extends GenericObject>(
  data: T,
  configs?: FormDataConfigs<T>
): FormData

Parameters

ParameterTypeDescription
dataTThe source object to convert to FormData.
configsFormDataConfigs<T> (optional)Configuration options controlling serialization.

Returns

  • FormData: A standard FormData instance containing the mapped inputs.

Example Usage

playground.ts

Behavior Details

Nested Objects

  • By default, nested objects are JSON-stringified (JSON.stringify) which is standard for modern API submissions.
  • Pass keys to dotNotateNested to flatten them recursively into dot-notated parameters (e.g. user.address.zip).

File Uploads

  • Automatically handles standard File, Blob, FileList, and file-upload formats from common UI Component Libraries (such as Ant Design).

Case & Whitespace Control

  • Trims all string values when trimStrings is true.
  • Converts specific key paths or values to lowercase using lowerCaseKeys and lowerCaseValues.

Warning

Server-Side Rendering (SSR): This utility is designed for browser environments and may fail or produce unexpected results when run inside server-side environments (such as Next.js Server Components) due to server-side FormData limitations.


Aliases

This function can also be imported under the following name:

AliasImport Path
convertToFormDatatoolbox-x/dom

Types

FormDataConfigs

interface FormDataConfigs<T> {
  ignoreKeys?: DotNotationKey<T>[];
  requiredKeys?: '*' | DotNotationKey<T>[];
  lowerCaseKeys?: '*' | DotNotationKey<T>[];
  lowerCaseValues?: '*' | NestedKeyString<T>[];
  dotNotateNested?: '*' | KeyForObject<T>[];
  stringifyNested?: '*' | KeyForObject<T>[];
  breakArray?: '*' | KeyForArray<T>[];
  trimStrings?: boolean;
}

Last updated: Mon, Jun 15, 2026 11:04:47AM (UTC)

On this page