How do I convert the entries from a HTML5 FormData object to JSON?
The solution should not use jQuery. Also, it should not simply serialize the entire FormData object, but only its key/value entries.
27 Answers
You could also use forEach on the FormData object directly:
var object = {};
formData.forEach(function(value, key){
object[key] = value;
});
var json = JSON.stringify(object);
UPDATE:
And for those who prefer the same solution with ES6 arrow functions:
var object = {};
formData.forEach((value, key) => object[key] = value);
var json = JSON.stringify(object);