Consuming API with Nodejs

Asked

Viewed 284 times

1

I am developing as study projects an API that consumes data from the Google API. I want my API that receives various data from the Google API to provide only the City and State data for the applications that will use my API.

How can I work to extract only this data from the JSON I receive from the Google API? I have no idea how to do it I’ve looked at several tutorials on You Tube but I can’t.

Below is my code and the answer my API delivers to the customer. inserir a descrição da imagem aqui

  • Welcome to [en.so]! You have posted an image of the code and/or error message. Although it sounds like a good idea, it’s not! One of the reasons is that if someone wants to answer the question, they can’t copy the code and change something inside. Click on the [Edit] link and put the code/error as text. See more about this in these links - Manual on how NOT to ask questions, Post Error Message as Picture

  • do not paste images, put text code in question

1 answer

-1


//Parsea os dados
const jsonParse = await JSON.parse(response.data)

//Acessando Propriedades do Json Retornado
res.json(jsonParse['results'][0])

//Ou se quiser acessar mais propriedades do json pode fazer desta forma
res.json(jsonParse['results'][0]['address_components'])

  • Thank you very much friend helped me D+

Browser other questions tagged

You are not signed in. Login or sign up in order to post.