@ajoelp/json-to-formdata
v1.5.0
Published
Convert json data to a FormData object
Downloads
1,413
Maintainers
Readme
JSON to FormData
Convert json data to a FormData object
Install
This project uses node. Install from their website
$ npm i @ajoelp/json-to-formdata
Usage
// 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);