I have a front-end application that sends a formData which contains arrays, so I'm using "object-to-formdata" to parse an the following object:

```
{
        "profileImage": {
            "name": "5574c060-853b-4999-ba39-1c66d5329704",
            "size": 364985,
            "mimetype": "image/png",
            "url": "uploads/5574c060-853b-4999-ba39-1c66d5329704"
        },
        "skills": [],
        "lessonsFinished": [],
        "classes": [],
        "_id": "5e3c2f8c80776b12cc336fdf",
        "email": "test@test.com",
        "password": "$2b$10$iZ3/BuklZ1FCGlyQDPUyMOhcWAfei5yl.llYScbWIv12XWcsokrgS",
        "username": "adrian",
        "verified": false,
        "status": "student",
        "color": "blue",
        "verificationCode": "50SZWPCHDL685C",
        "__v": 0,
        "lastName": "Test",
        "name": "Test",
    }

```

The object contains objects and arrays, and when parsed and sent to the backend, which uses express, with bodyParser and "express-fileupload" as a file manager, I receive this object:

```
{
    'profileImage[name]': '5574c060-853b-4999-ba39-1c66d5329704',   
    'profileImage[size]': '364985',
    'profileImage[mimetype]': 'image/png',
    'profileImage[url]': 'uploads/5574c060-853b-4999-ba39-1c66d5329704',
    'skills[]': '',
    'lessonsFinished[]': '',
    'classes[]': '',
    _id: '5e3c2f8c80776b12cc336fdf',
    email: 'test@test.com',
    password: '$2b$10$iZ3/BuklZ1FCGlyQDPUyMOhcWAfei5yl.llYScbWIv12XWcsokrgS',
    username: 'adrian',
    verified: 'false',
    status: 'student',
    color: 'blue',
    verificationCode: '50SZWPCHDL685C',
    __v: '0',
    lastName: 'Test',
    name: 'Test',
  }

```

I cannot seem to find a way of parsing this into a normal Object, since I need to use the full object as a query parameter for mongoose.

My Express configuration goes as follows:

```
const bodyParser = require('body-parser');
const fileUpload = require('express-fileupload');
const express = require('express');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(fileUpload())

```

Finally, I have the endpoint in which I am receiving the formData:

```
exports.create = function (model) {
    return async function (req, res, next) {
        try {
            let document = req.body;
            if (req.files) {
                Object.keys(req.files).forEach(key => {
                    let file = req.files[key]
                    file.mv(upload_dir + file.name, (err) => {
                        if (err) return res.status(500).send(err);
                    });
                    document[key] = {
                        name: file.name,
                        size: file.size,
                        mimetype: file.mimetype,
                        url: upload_dir + file.name
                    }
                })
            }
            const newDocument = await new model(req.body).save();
            res.status(200).send(newDocument);
        } catch (err) {
            return next({
                status: 500,
                message: err.message
            })
        }
    }
}

```

I receive the file just fine, and the rest of the data as well, but i cannot find a way of parsing the "encoded" (as in surrounded by brackets) object keys.
I tried building a recursive function to decode them but after several hours I couldn't find a solution and I figured there must be another way already working.

I tried the solutions presented in this thread: [How to convert FormData(HTML5 Object) to JSON](https://stackoverflow.com/questions/41431322/how-to-convert-formdatahtml5-object-to-json) but those just create an Object with the brackets included in the key...

Thank you in advance for the help!
['https://Stackoverflow.com/questions/60176340', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11101440/']
> 
> I know, any dynamically allocated memory MUST be freed at the end of its use, with `free()`.
> 
> 
> 

No. Not freeing has the result that less memory remains for your program to allocate for other purposes. It may (or may not) cause the program's memory footprint to be larger than it otherwise would be. In flagrant, extended, or extreme cases (as judged in an environment-dependent manner), it may mean that insufficient (virtual) memory is available to serve other applications, or to serve the leaky one itself. But none of those things mean you *must* free memory. You always have the alternative of accepting the consequences of not doing so.

For the most part, the minor advantages attending wanton disregard for freeing allocated memory in no way balance the negative impact on the program and on the system on which it runs, but there are cases in which it does not cause any practical problem. All major operating systems in use today release processes' allocated memory at process termination. Therefore, small leaks in short-running programs are fairly inconsequential on most systems you're likely to meet, and whether one should free memory that one needs to use until just prior to program termination is a matter of style, not practicality.

And that brings us directly to your example program.

> 
> However, is it an idiomatic function? If it exists, is it then considered a minor problem not to free the memory in this style of case?
> 
> 
> 

I think you meant "if it *exits*". As discussed above, there is substantially no difference in practical impact on the program or system between freeing manually just before exiting the top-level call to `main()` on one hand, and leaving it to the OS to clean up.

> 
> I would like to know if such a function can be used without worrying about freeing the memory every time, although I doubt it.
> 
> 
> 

You stand in grave danger of causing trouble for yourself and others if you neglect to free allocated memory without giving careful consideration to whether doing so will produce problems. You may under some circumstances go without freeing, but it would be foolish to do so without worrying about it, so to speak. Moreover, at your apparent level of experience, you may not yet be equipped to make good judgements in this area.

I would actually put it the other way around, then: being sure to free allocated memory when you no longer need it is the worry-free alternative. Or at least worry-less. You can make that relatively easy by cultivating programming practices that support it.
If you are on an operating system, where a misbehaving process can't really do much passive harm, then it is in practice fine. Active harm such as corrupting files is another thing, but leaving memory un-freed at program exit will not interact with those system APIs. So omitting memory free at program exit is, in a sense, always fine when program is running in such an operating system (such as any modern desktop OS).

From a different viewpoint, it is never fine. The reasons why include, from the top of my head:

* It's just not very smart to intentionally write non-portable code, when you don't *have to* for some reason. You never know what future brings.
* Being sloppy with memory while not being sloppy with other things, that's a difficult mindset to maintain. Just don't be sloppy with your code.
* What is now program exit might end up being just error handling function and resuming normal operation later, and then first of all it's easy to forget to fix the memory leak, and further you may have to do a lot of refactoring, when you suddenly need to have access to the pointer to be freed in a place where previously you had just thrown it away already.
* When they see leaks, other programmers will think poorly of the whole program, and as an extension, of the programmer who wrote it.
* In other languages, such as C++, freeing memory is coupled with calling cleanup code such as class destructor, and those in turn may for example flush buffers and close files, and not doing that can leave corrupt files etc. Better not develop bad habits with C, which you'd need to unlearn with different language.