Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't parse JSON from settings

I'm basing off one of the settings for my app on the Select component which is over here in the docs. 

 

The problem I'm having is that in the companion, I can't seem to get the text value from the setting. It's parsing the JSON into the following stringified object:

{"values":[{"name":"Calories"}],"selected":[1]}

I just want to get the "Calories" text, but any variation of JSON.parse(evt.newValue) is undefined.

I've tried JSON.parse(evt.newValue.values.name) and JSON.parse(evt.newValue.values[0].name) and nothing seems to work.

 

How would I get the string "Calories" from the parsed JSON?

Best Answer
0 Votes
2 REPLIES 2

Never mind, I figured it out. This is what works:

data = JSON.parse(JSON.stringify(JSON.parse(evt.newValue).values[0].name));
Best Answer
0 Votes

I don't think you need to double parse it.

JSON.parse(evt.newValue).values[0].name

 

Best Answer
0 Votes