In Javascript how can I convert a series of strings like the following into an Object that resembles my example?
indata = [
[ 'property.event.item1', 50 ],
[ 'property.event.item2', 12 ],
[ 'property.name', 'Dave' ],
[ 'data.items[]', 'butter' ],
[ 'data.items[]', 'milk' ],
[ 'data.items[]', 'cheese' ],
]
The value of indata is coming from a submitted HTML form. I want to convert it into JSON like the following:
outdata = {
"property": {
"event": {
"item1": 50,
"item2": 12
},
"name": "Dave"
}
"data": {
"items": [ "butter", "milk", "cheese" ]
}
}
I could either do it in JS before I submit it and submit the reconstructed JSON data, or I could accept the form as-is on the backend and convert it with Python. I have not had to deal with the complications of reconstructing form data into JSON before and I am struggling with a concise way to do this.
I’ve considered using FormData() (in JS) or flask.request.form.to_dict() (in Python) but I am not coming up with viable solutions. Does anyone know of a library to help with this, or can anyone see a simple solution using built-ins?