view raw
Tom C Tom C - 8 months ago 37
JSON Question

JSON javascript display value undefined

I have a JSON object returned which looks like this

"competition": {
"name": "Premier League",
"nextState": 1,
"team_id": 1
}, {
"competition": {
"name": "Premier League",
"nextState": 1,
"team_id": 2

This a slimmed down version of the JSON, I am trying to access say the team_id

result = JSON.stringify(result, null, 4);



All I seem to get is undefined, am I not access this correctly?

Many thanks


You have stringified your object result to a string. So for sure you can not access the attributes anymore.

Use a second variable for the stringified result:

var result_stringified = JSON.stringify(result, null, 4);