"get json with jquery" - where does data come from

"get json with jquery" - where does data come from
0

#1

Where does the JSON data come from in this exercise #249?
The code is
$.getJSON("/json/cats.json", function(json) {
$(".message").html(JSON.stringify(json));
});

This works great so long as I run this code from within FreeCodeCamp.

But, if I try to run the code in CodePen or Cloud9, the path to the /json/cats.json file cannot be found.

Can I create a JSON file with the same info?
How would the url for the call to the json file change?


#2

It would be the URL of wherever you put the file. If the file was in the same filesystem you can use relative paths, so for example if it was in the same folder, “./cats.json”


#3

The JSON file used in this challenge contains the following array of objects:

[
  {
    "id": 0,
    "imageLink": "https://s3.amazonaws.com/freecodecamp/funny-cat.jpg",
    "altText": "A white cat wearing a green helmet shaped melon on it's head. ",
    "codeNames": [
      "Juggernaut",
      "Mrs. Wallace",
      "Buttercup"
    ]
  },
  {
    "id": 1,
    "imageLink": "https://s3.amazonaws.com/freecodecamp/grumpy-cat.jpg",
    "altText": "A white cat with blue eys, looking very grumpy. ",
    "codeNames": [
      "Oscar",
      "Scrooge",
      "Tyrion"
    ]
  },
  {
    "id": 2,
    "imageLink": "https://s3.amazonaws.com/freecodecamp/mischievous-cat.jpg",
    "altText": "A ginger cat with one eye closed and mouth in a grin-like expression. Looking very mischievous. ",
    "codeNames": [
      "The Doctor",
      "Loki",
      "Joker"
    ]
  }
]

It is located at https://www.freecodecamp.org/json/cats.json