Juan Badal
Juan Badal

Reputation: 71

read json data from a request nodejs

im trying to read json data and get the price of ETC. The problem is that the path to get the price in usd has a "-" in the ethereum-classic name and im getting errors.

        url = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum-classic&vs_currencies=usd";


        request(url, (err, res, body) => {


            const data = JSON.parse(body);
            const item = data.ethereum-classic.usd;

Upvotes: 0

Views: 36

Answers (1)

Junior Ngangeli
Junior Ngangeli

Reputation: 112

Did you try something like this ?

const item = data["ethereum-classic"].usd

Upvotes: 1

Related Questions