JavaScript Tip: Loading a Local JSON File without Fetch

preview_player
Показать описание
Loading a local JSON file is frequently done with fetch. But that is not the only way to accomplish this. In this tutorial we are going to look at a method for loading a local JSON file without using fetch.

Would you like to help keep this channel going?

Tutorials referred to in this video:

For more resources on JavaScript:

#javascript #AllThingsJavaScriptLLC
Рекомендации по теме
Комментарии
Автор

I've been searching for hours and ended up on this video. Thanks a million tons!

junkord
Автор

This is exactly what I was looking for ... makes my code so much more streamlined!

NicoHeinrich
Автор

i can't stop watch 3 hour continuous, amazing

ahmedalsagir
Автор

This only works with Chrome. It does not work with FF just a heads up. If you try to run this with FF you will have issues and it will not load the array since FF does not support import assertions.

darrenlo
Автор

Thanks! Excellent video. This method is great for when your app’s json data is on the same server as the app itself. No need to wait for the json. Promises can be avoided making coding easier/less complex

TillmanTech
Автор

Thanking for saying you would link something in the description, and remembering to link it

ivangutowski-smith
Автор

God bless you, sir. You're one of the few finest YouTube instructors on JavaScript, including Kyle from WebDev Simplified and Professor Steve Griffith.

septimusforster
Автор

Many thanks for this, I’ve sometimes wanted to try some stuff out using a mock data file i JSON format, but I’ve usually given up after getting that second error message.
Now I know why it happens.

_V__.
Автор

So helpful thank you! The console gave an error saying that 'assert' is now a depreciated statement with the new chrome update and to use 'with' instead. Made that change and it worked like a charm!

Allison-fbqp
Автор

Thanks for sharing this. I found this example to work well when using Google Chrome as the target, but when using FireFox - it reports; "Uncaught SyntaxError: import assertions are not currently supported".

karlstenator
Автор

At this time, Firefox still doesn't support assertions. Otherwise this works great.

estral
Автор

I have a question. How can I import data of a nested array in the JSON
i have made a script to pull data from an SQL server, which works fine but outputs a file set like this
[
[
{
Objects
}
A bunch more objects
]
]

And I've been using a script I've found to display it in HTML, but the script doesn't understand the nested array

nyarlathotepthecrawlingcha
Автор

Simple and Stright to the point. Thank you.

madhavig
Автор

Everything else seems to work for me now. BUT, I need the .json file to read as an object or variable like dictionary so i can process the data from it in Javascript. How can i store the data that is read into a variable like object? I need it to be able to read similar to how python read dictionaries

mikhailwebb
Автор

Thank you very much! You helped me out

vzidwdh
Автор

So how do you resolve "Cross origin requests are only supported for HTTP."

cymlqes
Автор

Then could you console.log(users.name) and it print out the ane of the users?

HollowsDarkness
Автор

Thx, such useful info!
Warmest greetings from Ukraine!

Erebor
Автор

I got an error "Uncaught SyntaxError: Unexpected token ':' " for my json file

xc
Автор

newbie here! Is it possible to update the content of the JSON file?

oreki