I am trying to create a JSON and populate it with some data. The data is a bit complex so I would like to have its "title", "name" and "value".
My issue is that I am not able to get the content from the JSON I created and getting "Uncaught SyntaxError: Unexpected token o" error message. However, if I just pass the json variable to console.log() I can see all the objects contained in the variable.
Please see the code below:
JSON
var json = [
    {"title":"rice",
        "value":{
            "carb": 44.5,
            "fat": 0.1,
            "cal": 205,
            "prot": 4.3
        }
    },
    {"title":"buckwheat",
        "value":{
            "carb": 20,
            "fat": 1,
            "cal": 92,
            "prot": 3
        }
    },
    {"title":"potato",
        "value":{
            "carb": 50.5,
            "fat": 0.5,
            "cal": 225,
            "prot": 5.9
        },
    }
]  
JS
var obj = JSON.parse(json);
console.log(obj[0].title);
 
     
     
    