/* Json data looks like an array with loads of JavaScript objects inside it, but it's not. It's just a string. The string is formatted in a way that looks like JavaScript objects with curly braces and key value pairs, but it is still just a string and that's all Json essentially is , strings which look like JavaScript objects and it has to be a string because when a browser exchanges data with a server, it has to be done in text format. That is the format of data transfer and that is why we use this format Json. */ /* So what we need to do is figure out a way of taking the Json string and turning it into a real JavaScript object so that we can access all of the different properties inside. */ /* JSON.parse(); --> this method So this method takes in a Json string. And then what it does is convert that Json string into JavaScript objects that we can then use easily in the code. */ const getTodos = (callbackFunction) => { const request = new XMLHttpRequest(); request.addEventListener("readystatechange", () => { if (request.readyState === 4 && request.status === 200) { const data = JSON.parse(request.responseText); callbackFunction(undefined, data); } else if (request.readyState === 4) { callbackFunction("could not fetch data!!", undefined); } }); request.open("GET", "todos.json"); request.send(); }; getTodos((error, data) => { if (error) { console.log(error); } else { console.log(data); } }); /* So whenever we make a request to some kind of endpoint and it's serving us back some Json data, essentially what it's doing on their server, it's getting some Json from somewhere like we've got Json from todos.json file and it's just sending that Json back to us to the browser. It's a way of transferring data between server and client. */