Get particular value from json string in Aura component

apexaurajsonlightning-aura-components

I have below code where I am converting json.stringify and getting below output

let theData = JSON.stringify(helper.getData(component));
console.log('theData>>>' + theData);

output:

{"userName":"[email protected]","profile":"Sales","Account":"Self","Contact":"Personal","Time":"IST"}

I need to get profile value in one var/let, but I am not able to understand how I can get the specific value.

I tried this but not working

var Profile = theData[0].get('profile'))   

getting error. Please help

Best Answer

first you don't need to do JSON.stringify because its returning object.
so you can simple get profile value using below code

let theData =helper.getData(component);
console.log(theData.profile);

second way:
let theData = JSON.stringify(helper.getData(component));
let output = JSON.parse(theData);
console.log(output.profile);

Hope its help

Related Topic