I have a request I receive through a webhook which returns the following object as req.body:
{"appId":"7HPEPVBTZGDCP","merchants":{"6RDH804A896K1":[{"objectId":"O9FN4R9BMKXQ0","type":"UPDATE","ts":1686754357822},{"objectId":"OE87DT9330H7R","type":"UPDATE","ts":1686754358007}]}}
The issue i am having is although I can access the merchants through req.body.merchants, that is a key/value pair with the key being a string and the value being an array as:
{"6RDH804A896K1":[{"objectId":"O9FN4R9BMKXQ0","type":"UPDATE","ts":1686754357822},{"objectId":"OE87DT9330H7R","type":"UPDATE","ts":1686754358007}]}
The issue i am having is that I need a way to access the key of merchants, 6RD8H04A896K1
, as well as the value which is:
[{"objectId":"O9FN4R9BMKXQ0","type":"UPDATE","ts":1686754357822},{"objectId":"OE87DT9330H7R","type":"UPDATE","ts":1686754358007}]
I tried the following but had no luck:
const merchantResponse: { id : value} = req.body.merchants;
but that doesn't seem to work either. Can someone tell me how I can convert this nested key/value pair into a json object and access its values? The issue is I do not have the object key otherwise I could have just called it as:
const merchantResponse = req.body['6RDH804A896K1'];
anyone have a solutions to this problem?