Jump to content

(javascript) How can I store data from an API as json

RTX 3090

Hi, I am trying to get data from an API, which works fine, but I need to be able to parse that data afterwards and select a specific part of it. I am getting an error and am not to sure why, I have been banging my head against it for an hour now, with no success

let url = "URL goes here"


function getData(url, cb) {
  fetch(url)
    .then(response => response.json())
    .then(result => cb(result));
}

getData(url, (data) => console.log({ data }))

const obj = JSON.parse(response.json);

And this is the error I am getting

image.png.d00e8472c89e04962f03dd1a542a9401.png

 

Help is greatly appreciated, thanks

Please tag me @RTX 3090 so I can see your reply

Link to comment
Share on other sites

Link to post
Share on other sites

-> Moved to Programming

^^^^ That's my post ^^^^
<-- This is me --- That's your scrollbar -->
vvvv Who's there? vvvv

Link to comment
Share on other sites

Link to post
Share on other sites

try the below.

 

(async function(){
  let url = "URL goes here";
  let result = await fetch(url);
  let result_json = await result.json();
  console.log(result_json);
})();

 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×