I have been struggling to access the elements of a nested object without any success. Despite looking through similar questions on stackexchange (such as this), I have not been able to resolve my issue. I attempted to access the final element using console.log(result.final), but it returned undefined in the console. Any help would be greatly appreciated.
var data = '{"response":{"valid":true,"final":{"message":" MS02","tags":{"d1":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiJ9","d2":"JhbGciOiJIUzI1NiJ9eyJ0eXAiOiJKV1QiLC","d3":"dupb9WWT8ypQYWw6QblkM98xFBBRsamkkWLw","d5":"5EChV1KJ4ASeh9crZDR3fivnSz4wCDmCr2RSC0CUrkx","d6":"hiH1I1SI3NHCYZeva0_FrjgSgxOa_YW6ECxRdAY-w5w","ua":"y"},"ti":"","op":[]}}}';
var dataJson = JSON.parse(data);
var result = [];
result = Object.entries(dataJson).map(([key, value]) => ({ [key]: value }))
console.log(result)
console.log(result.final)
UPDATE
Upon using typeof
on dataJson
, it was identified as a string
. Subsequently, I performed an additional JSON.parse
on dataJson
, and upon rechecking with typeof
, it showed as an object
. Now, after double JSON.parse
, I successfully accessed the nested values using the dot operator (result.final), without the need for mapping.