Importing JSON files to JS

Hi i’m new to html/css/js and have been experimenting in building a website here on Replit.

https://replit.com/@RussellThomas3/PlayoffsREPLIT

I used chatgpt to generate most of the code for this. I was unable to import the json files to my main.js and have it populate my html file so i ended up just pasting in my data into the js file. Is there something special i need to know about importing json files into a .js on Replit for this HTML/CSS/JS template? i was trying to import ‘series_dict.json’. Do I need to include anything else in the filepath or address for this for it to import?

thank you!

Welcome to the community, @RussellThomas3! I am amlost positive that .js is JavaScript. To do a json file you literally have to do .json. I might be misunderstanding you but I hope that this helps you. :smiley:

They… know that… Did you look at the Repl?-

Their question is how to get the data from their json files into their js files.


To me this sounded like they were trying to directly put a json file into a .js lol

My brain is absolutely fried rn ngl…

EDIT: my title may say “Champion” but rn I feel more like this
image

1 Like

Hello, you can use the fetch API to import JSON. (Also, don’t use ChatGPT for everything, AS IT IS WRONG SOMETIMES). Plus, that is bad for the brain, as it limits its capabilities of problem solving.

fetch("series_dict.json")
  .then((res) => {
    return res.json();
  })
  .then((json) => {
    // do what you want with the JSON
  })
2 Likes