I'm currently working with a payload that is string and im parsing is using JSON.parse(payload)
. My question is, once I convert the payload I need to access at least 5 properties within the newly created JSON object and it is quite nested. My current implementation is:
....then(payload => {
return ({
obj1: JSON.parse(payload).field.obj1
obj2: JSON.parse(payload).field.obj2
obj3: JSON.parse(payload).field.obj3
obj4: JSON.parse(payload).field.obj4
obj5: JSON.parse(payload).field.obj5
});
})
I feel like this is to much repetition and feel this way would work better in terms of readability (even then it is not that clean):
....then(payload => {
let jsonObj = JSON.parse(payload)
return ({
obj1: jsonObj.field.obj1
obj2: jsonObj.field.obj2
obj3: jsonObj.field.obj3
obj4: jsonObj.field.obj4
obj5: jsonObj.field.obj5
});
})
Can anyone suggest the best way to execute this in terms of readability and performance?
NOTE: This is used within a promise.all()
so the above will iterate over X promises.