I am trying to read this json string in Javascript so that I can access its node. However I get undefined.
const jsonStr = '{"data":"{\"page\":\"1\",\"firstName\":\"c\",\"company\":\"\",\"reqValidation\":false,\"notes\":\"\",\"roles\":[],\"level\":\"beginner\"}"}';
I am trying to read the data in JS using :
jsonStr.data or jsonStr.['data']
gives me undefined
.
I tried to use JSON.parser(jsonStr);
, I get :
Uncaught SyntaxError: Unexpected token p in JSON at position 11
at JSON.parse (<anonymous>)
The JSON is produced using below. The data part is what I am trying to read in another JS file.
const data = JSON.stringify({
page: "1", firstName: this.firstName, lastName: this.lastName, company: this.company, reqValidation: isValid,
notes: this.notes, roles: this.roles
});
const nextEvnt = new CustomEvent('initiate', {
detail: { data }
});
this.dispatchEvent(nextEvnt);