Juan Badal
Juan Badal

Reputation: 71

How to control json data nodejs

im making a bot to get the price of the peso argentino. Im using a Api but im having some problems to get only the sell price.

if (command == "peso"){
    request('https://www.dolarsi.com/api/api.php?type=valoresprincipales', (err, res, body) => {
    
        const data = JSON.parse(body);
        message.channel.send(body);
});

Im getting this output: enter image description here

And I need to get only this price: enter image description here

Upvotes: 0

Views: 45

Answers (1)

KShewengger
KShewengger

Reputation: 8269

If you only want to get that particular sell price, you must be particular on what property you want to compare to get that sort of data.

Example:

const data = JSON.parse(body);

const item = data
   .find(({ casa: { venta } }) => venta === "161,000")
   .casa
   .venta;

Attach is the Stackblitz Demo for your reference with the mock data in reference to your screenshot above

Upvotes: 1

Related Questions