Hello,

I’m kind of new to working with APIs and I’m getting a little stuck with extracting the data from the json response(s). I’m trying to use the API responses in order to decide whether or not to show the user content on the webpage.

I’m using the following code:

const fetch = require('node-fetch');

let url = “apigoeshere”;

let settings = { method: “Get” };

fetch(url, settings) .then(res => res.json()) .then((json) => {

console.log(json.properties.firstname);

This allows me to take the objects which are inside of objects but I really cannot work out how to get the data out of an array of objects. I’ll include a screenshot at the end to make things easier for people to visualise.

I’m trying to get at the fields (mainly the title or ID) inside of the “form-submissions” array. I’ve tried a number of things and the clocks just dinged midnight and I’m still not getting it. I’ve tried things like json.form-submissions[0].title or [‘title].

No doubt I am doing it wrong and it’s a simple thing but after several hours of trying my own things I feel it’s time to ask for help to help me move onto the next step of learning.

Apologies for having to blank areas out but as they’re forms they contain personal information.

r/webdev - Would anyone be kind enough to help me out with working with json responses? Image inside.

If anyone can point me in the right direct I’d really appreciate it. I appreciate this is also going to be trivial to some of you but I just can’t get my head around getting the data out. Alway get the response from node that what I’m trying to pull is undefined.

Thanks,



Source link

Write A Comment