I am new to Node and struggling to access a simple JSON object. My request.body will have JSON content similar to the following:
{
"store_config": [
{
"name": "hello",
"name2": "world"
}
]
}
The "store_config" value will always be present, however the keys and values within could be anything.
How can I iterate through the keys and values to access each? I would also like to process each in an asynchronous manner.
Appreciate any thoughts or direction.
UPDATE
console.log(typeof(request.body));
Returns: Object
parsedBody = JSON.parse(request.body);
returns:
SyntaxError: Unexpected token o
at Object.parse (native)
UPDATE 2 - Further debug:
When I try to iterate through the array, there is only a single value:
request.body.store_config.forEach(function(item, index) {
console.log(index);
console.log(request.body.store_config[index]);
});
returns:
0
{ name: 'hello', name2: 'world' }