JSON array directly in request body is interpreted as Object
See original GitHub issueSupport plan
- Which support plan is this issue covered by? (Community, Sponsor, Enterprise): Community
- Currently blocking your project/work? (yes/no): yes
- Affecting a production system? (yes/no): no
Context
- Node.js version: 16, but probably all
- Release Line of Formidable (Legacy, Current, Next): v2
- Formidable exact version: 2.0.1
- Environment (node, browser, native, OS): node
- Used with (popular names of modules): express
What are you trying to achieve or the steps to reproduce?
function formidableMiddleWare(options = {}) {
return (req, _res, next) => {
const form = formidable(options);
form.parse(req, (err, fields, files) => {
if (err) {
logger.error('Parsing of form', options, err);
next(err);
return;
}
req.body = fields
next();
});
};
};
app.post(
'/form',
formidableMiddleWare({
// Do not accept any file by default!
filter: () => false,
}),
(req, res) => {
res.json({
req,
isArray: Array.isArray(req),
});
},
);
What was the result you got?
The result of form.parse
is an Object
not Array
What result did you expect?
The result of form.parse
should be an Array
.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
java - How to directly read this JsonArray which comes in a ...
How to directly read this JsonArray which comes in a RequestBody ; @PostMapping("/certificates") public ResponseEntity<String> postCertificates ...
Read more >Convert JSON Response Body to Java Object - Tools QA
This tutorial explains How to convert or parse JSON Response Body to Java Object (POJO) using Deserializing in Java with examples.
Read more >How JSON Array of String Works? (Examples) - eduCBA
We have seen how JSON array represents an ordered list of values be it string, numbers, Boolean, or an object. Here as per...
Read more >JSON Stringify Example – How to Parse a JSON Object with JS
JSON arrays work pretty much the same way as arrays in JavaScript, and can contain strings, booleans, numbers, and other JSON objects.
Read more >How to create JSON Array Request Body
In the last tutorial, I explained How to test POST JSON Object request using Java Map in Rest Assured. In this tutorial, I...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
How is this a solution to this problem?
Don’t use webpack