My node app receives this json:
{
"team":"Man UTD"
,"playersAndRoles":
{
"Pogba":["Midfielder"]
,"Martial":["Striker","Wing"]
,"Ibrahimovic":["Striker"]
}
}
Now, I read this json with this code:
var jsonBody = req.body;
console.log('jsonBody.playersAndRoles.length', jsonBody.playersAndRoles.length);
However, the length is undefined. The JSON is valid. But Im not sure if the way the json represents array is correct. I can modify the JSON. If it is written in wrong way.
But the received JSON seems OK. because I can do this:
console.log('jsonBody.team', jsonBody.team); //Prints Man UTD
So I guess the wrong part is the definition of the "playersAndRoles" object. Is that correct?
PS: If I try to run a:
JSON.parse(jsonBody.playersAndRoles);
then it throws an exeption.