https://github.com/ajoelp/json-to-formdata
Convert json data to a FormData object
https://github.com/ajoelp/json-to-formdata
data form formdata json object
Last synced: about 1 year ago
JSON representation
Convert json data to a FormData object
- Host: GitHub
- URL: https://github.com/ajoelp/json-to-formdata
- Owner: ajoelp
- Created: 2019-10-08T23:14:34.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-20T15:32:26.000Z (about 3 years ago)
- Last Synced: 2025-03-25T16:55:53.816Z (about 1 year ago)
- Topics: data, form, formdata, json, object
- Language: TypeScript
- Homepage:
- Size: 1.33 MB
- Stars: 14
- Watchers: 1
- Forks: 4
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON to FormData
> Convert json data to a FormData object
## Install
This project uses [node](http://nodejs.org). Install from their website
```shell script
$ npm i @ajoelp/json-to-formdata
```
## Usage
```javascript
// Using ES6
import jsonToFormData from '@ajoelp/json-to-formdata';
// Using CommonJS
const jsonToFormData = require('@ajoelp/json-to-formdata');
// Use the package
const formData = jsonToFormData({
foo: 'bar',
bar: 'baz',
});
// With options
const formData = jsonToFormData({
foo: 'bar',
bar: 'baz',
}, {
// Add indexes to arrays
arrayIndexes: true,
// Exclude nulls from data items
excludeNull: true,
});
// Append an existing FormData Object
const formData = new FormData();
formData.append('key', 'value');
jsonToFormData({
foo: 'bar',
bar: 'baz',
}, {}, formData);
```
## License
[MIT License](https://opensource.org/licenses/MIT) © [Joel Podrebarac](https://joelpodrebarac.me/)