Now that we set up a feed you, Earl, we need to get that information restructured and build out our
new mydata object with that feed content, and in this case, we can also use that event listener in
order to trigger the retrieval of the feed data and then updating of the content of the mydata object
that we created in the last lesson.
And then over here is we want to load JSON so we create a function in order to load JSON and this function,
I'll move this down afterwards.
So we've got a function where we load the JSON data and we're going to we've already built out our feed
you or else we do have that already in place.
And the other thing that we need to do is we need to create our fetch.
So fetches JavaScript and its promise based method that can do a promise of fetch.
You fetch the Eurail or whatever file location you want to fetch, and then you've got the promise which
is invoked when the content is being returned.
So this is the return of the content from Fetch and then he can string together multiple promises.
So over here we've got the content being returned back and we can also specify that's being returned
back in adjacent format.
So what happens here is we've got our response and within the response, we've got a ton of information
there.
So remember, this is a promise based format.
So once it gets the response, then we can return back a second part to it.
And that's where we can format that content as JSON content and do a return and then add in one more
promise where we can handle that data.
So now it's coming in as data and will console log this part out the step out as well.
So we're getting that content in as data.
So when we refresh first we get the response and then we get the data and the data is all contained
here within the feed.
And this is the exact same stuff that's being output here.
And the one that we're after are the entries you see here.
We've got the entries.
These are the same ones that we looked at earlier with the.
So that's the data that we want to make use of when we're pulling back that feed information.
So what we want to do here is we want to loop through that feed data.
So taking data as we've got it now within the data object, and because it's an object, we can go into
feed and then we can go down to entry and entry contains is an array.
So that means that we can loop through that array, returning back each one of the items that's available
within the array.
So we're going to do another function in here and this can be item.
And so let's console log item now.
And because it is fairly complex, the JSON feed, that's why we got to do a little bit of work here
to try to get to the data that we're looking for.
So now item is being represented in this type of format and we have to break apart item as we loop through
it.
So before we loop through it, I want to return back each one of those item values.
And again, we need to loop through this.
So this is another array of different values here that are contained within the item.
So C item is not just one value that's being returned back.
We've got quite a few of them and I want to loop through each one of those as well.
And because this is an object, we can get the key of the element.
So for let key.
So this is going to return back all of the keys.
So console log.
And I know we've got quite a lot going on in this console and it might be a little bit hard to break
through this, but now we see that we're getting this is item and then these are the keys that we're
seeing.
So the keys that we're interested in are these geia six keys.
Those are the ones that we want to use so we can take the value of key and we can see if it's starts
with sex.
And if it does, then this is a key that we want to look at and we want to add to our larger array.
So using key substring, returning back the first three characters of the key substring and we're checking
to see if it starts with sex.
And if it does, then those are the ones that we're interested in.
There's a little bit of cleaning through here, but as we clean through here, you're going to see that
now we're only returning the ones that have sex.
And remember, these sex ones correspond with the headings.
And this means that we're getting all of the values that we want.
And you can see that as we iterate through each one of those rows, we're getting the values that we
want.
So the next thing that we want to do is we want to split and we want to add to a main holder array.
So we set up a holder array in order to accommodate that.
So setting up another variable and we can call this holder.
And then as we loop through, we can update it and we can put.
Start value and the value that we want to push in is going to be the content after the dollar sign.
So we've got to do one more thing where we take the value of key and then we know that this is the one
that we want.
We're going to split it by the dollar and then we're returning back that first item that's available
for us.
So what's going to be returned back here is those values that are contained.
So we see test course rating and so on.
So these are going to be the heading values.
And we don't actually want the heading value.
We want the T value.
So this is the way to get the heading.
And we can also get the T value if we want.
And this is all possible because this is an object and an object format and return back the value of
T so sure.
What that looks like as well.
So we'll consult logout that.
So now we can see that we're returning back to heading the name heading name, heading name.
And the one that we wanted to add into the array is going to be the the the key.
So after we've loop through all of this, we can console log out holder and you can see that Holder
now is going to contain all of those value.
And the thing is here that this is just that one row of content.
So and we know that the structure that we're looking for and looking to build.
So this is an array within an array.
So we need to set up one more array as our main container that's going to hold all of that information.
So let's set up one more main array and starting out as blank.
And as we iterate through each one of these, then we want to add it to we want to add Holder into the
main array.
So one last piece that we need to do, and this is going to be main array and we're pushing the value
of Holder into it.
So once we finish and once we've finished doing all of the loops, let's put the value of main array.
So we can see what it turns out to be.
So structure is starting to look better and more of kind of what we want, where we've got multiple
arrays within an array and we've got all of the contents there, but we don't quite yet have our headings.
So that's another one that we need to add in.
And there's a number of ways to do that.
So in this case, what we'll do is we'll just create another variable to hold the heading.
We can call this heading and this is another array that's going to hold it.
And then as we loop through, so the first time through, what I want to do is I want to add the values
of this.
Two heading, so we'll check to see if heading and remember, we're getting those those key values there
that we can use.
So we're check to see if heading length and of heading length is we're probably better off to set a
boolean value.
So we call this first run and setting it to.
And only if this is true, then we're going to build another array for heading.
So if first.
Run.
So the first run is true, then what we'll do is we're going to take our heading away and push that
value into it.
So this is the value here.
And remember, this is the heading values.
So we're pushing it into the heading array.
And we're also going to do one more check before we complete that main array and before we add Holder
to the menary.
And that's going to be the check to see if it's first run.
And if it is first run, then we're going to set the value of first run to be false so we don't add
any more to heading.
And we're also going to take the the main array and we're going to push heading into it.
There's quite a bit of work usually in order to structure things the way you need it.
So right now it looks like we've got it fairly good and fairly much as needed.
And we're ready to add in this data into our data instead of using my data.
Now that we've loaded this content, we can add and update the my data as my array.
So now when we refresh and we download and we open up our download value, remember, it's comma separated.
You can see that now we've made a duplicate of what's available in our spreadsheet.
So we've got all of that content there and available.
So I know this was a fairly long lesson and it does take some time to kind of go through and restructure
the data, especially when the JSON feed is this big and it's got so much complexity to it.
So it's not always ideal, but it is something that you can work with and you can restructure.
And if you're not familiar with working with Jason, then I do suggest to use things like Jason Lente
in order to familiarize yourself a little bit better with what's being represented here within this
JSON object, and then also how you can break that apart and get the values that you need in order to
restructure and build out within the format that you need in order to output to a CSFI file.
So go ahead and try it out for yourself and see if you can first restructure the content within the
format that you need in the mydata.
And then once it's there and once it's ready, then you can simply equal my data to the mihiri that
you've built and download the CSFI file and you're going to have that updated version, all the content
coming from the Google spreadsheet.
So come up next, we'll do a quick Coldren.