{"library":"object-to-formdata","title":"Object to FormData Serializer","description":"object-to-formdata is a utility library for JavaScript that efficiently serializes plain JavaScript objects into `FormData` instances, a crucial browser API for sending data via `multipart/form-data` requests. Currently at version 4.5.1, it provides options to control how arrays, nulls, booleans, and object/array notation in keys are handled during serialization. The package is actively maintained with regular updates and bug fixes, indicated by its recent releases. Its primary differentiator is the configurable serialization logic, allowing developers to fine-tune how complex data structures are represented in `FormData` compared to manual construction or simpler serializers.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install object-to-formdata"],"cli":null},"imports":["import { serialize } from 'object-to-formdata';","const { serialize } = require('object-to-formdata');","import type { FormData } from 'object-to-formdata';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { serialize } from 'object-to-formdata';\n\nconst userProfile = {\n  name: 'John Doe',\n  email: 'john.doe@example.com',\n  age: 30,\n  isActive: true,\n  roles: ['admin', 'editor'],\n  address: {\n    street: '123 Main St',\n    city: 'Anytown',\n    zip: '12345'\n  },\n  avatar: new File([''], 'avatar.png', { type: 'image/png' })\n};\n\nconst options = {\n  indices: true, // Serialize roles[0]=admin, roles[1]=editor\n  booleansAsIntegers: true, // Serialize isActive=1\n  nullsAsUndefineds: true, // Ignore null values\n  dotsForObjectNotation: false // Use brackets for objects (address[street])\n};\n\nconst formData = serialize(userProfile, options);\n\n// To see the contents (FormData is not directly iterable by value without special methods):\nfor (const pair of formData.entries()) {\n  console.log(`${pair[0]}: ${pair[1]}`);\n}\n\n// Example of appending to an existing FormData instance\nconst existingData = new FormData();\nexistingData.append('tenantId', '123-abc');\nconst combinedFormData = serialize({ metadata: 'important' }, {}, existingData);\n\nfor (const pair of combinedFormData.entries()) {\n  console.log(`Combined: ${pair[0]}: ${pair[1]}`);\n}","lang":"typescript","description":"Demonstrates basic serialization of a complex JavaScript object, including files, arrays, and nested objects, into a FormData instance using various configuration options, and appending to existing FormData.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}