God bless you, sir. You're one of the few finest KZbin instructors on JavaScript, including Kyle from WebDev Simplified and Professor Steve Griffith.
@AllThingsJavaScript Жыл бұрын
Glad to help! Thanks!!
@NicoHeinrich2 жыл бұрын
This is exactly what I was looking for ... makes my code so much more streamlined!
@AllThingsJavaScript2 жыл бұрын
Glad it helped!
@junk1ord2 жыл бұрын
I've been searching for hours and ended up on this video. Thanks a million tons!
@AllThingsJavaScript2 жыл бұрын
Glad I could help!
@darrenlo11652 жыл бұрын
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.
@ahmedalsagir2 жыл бұрын
i can't stop watch 3 hour continuous, amazing
@karlstenator2 жыл бұрын
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".
@AllThingsJavaScript2 жыл бұрын
Thanks for reporting that firefox doesn't support insertions yet!
@ivangutowski-smith65142 жыл бұрын
Thanking for saying you would link something in the description, and remembering to link it
@abduljamadar99254 ай бұрын
I was looking for this solution from past 2 days. Thank you sir.
@AllThingsJavaScript4 ай бұрын
Glad it helped!
@mikhailwebb83772 жыл бұрын
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
@AllThingsJavaScript2 жыл бұрын
When the JSON file is parsed, it is a JavaScript object that you can work with. Perhaps these tutorials will help: kzbin.info/www/bejne/hpOQaXewdrSVo8k and kzbin.info/www/bejne/r4CZaIpqqalphrM
@mikhailwebb83772 жыл бұрын
@@AllThingsJavaScript Thanks for your reply. I resorted to using python to finish the implementation.
@4estral Жыл бұрын
At this time, Firefox still doesn't support assertions. Otherwise this works great.
@umangternate Жыл бұрын
I got "import assertions are not currently supported"
@AllThingsJavaScript Жыл бұрын
Are you running your files from a local server?
@umangternate Жыл бұрын
@@AllThingsJavaScript yes sir, I was using WAMP server. But I figured out that it was the browser. Mozilla FF does not support it currently. When I use Chrome, it ran smoothly.
@madhavig530211 ай бұрын
Simple and Stright to the point. Thank you.
@AllThingsJavaScript11 ай бұрын
You're welcome!
@ArvindMMittal6 ай бұрын
Great! So simple.
@cxkcxk-o6d Жыл бұрын
So how do you resolve "Cross origin requests are only supported for HTTP."
@AllThingsJavaScript Жыл бұрын
It requires among other things changes on the server. Search resolving cross origin requests for lots of info on it.
@abdullahkhurram98472 ай бұрын
still i have a problem : Uncaught SyntaxError: Unexpected identifier 'assert' (can you help???)
@AllThingsJavaScript2 ай бұрын
Can you provide a bit more information? Where is assert in your code? Maybe provide you code.
@Erebor99700 Жыл бұрын
Thx, such useful info! Warmest greetings from Ukraine!
@AllThingsJavaScript Жыл бұрын
Glad it was helpful! Our prayers our with everyone in Ukraine.
@_V__.2 жыл бұрын
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.
@AllThingsJavaScript2 жыл бұрын
Glad it helped!
@oreki19962 жыл бұрын
newbie here! Is it possible to update the content of the JSON file?
@AllThingsJavaScript2 жыл бұрын
The best way to update a JSON string is to convert to an object (JSON.parse) update the object and then convert back to a string (JSON.stringify).
@oreki19962 жыл бұрын
@@AllThingsJavaScript will try! thank you so much
@jayantagarwal63392 жыл бұрын
you really saved my day
@AllThingsJavaScript2 жыл бұрын
Glad to help!
@nyarlathotepthecrawlingcha9692 жыл бұрын
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
@AllThingsJavaScript2 жыл бұрын
Once you have the JSON data, you just need to access it like a normal array/object. See if this tutorial helps: kzbin.info/www/bejne/r4CZaIpqqalphrM Or maybe this one kzbin.info/www/bejne/n2PImGWuecedg5I
@prinzadamz3 ай бұрын
Thanks a ton 🤘👍
@AllThingsJavaScript3 ай бұрын
Glad it helped!
@xc4945 Жыл бұрын
I got an error "Uncaught SyntaxError: Unexpected token ':' " for my json file
@AllThingsJavaScript Жыл бұрын
Looks like there may be an error in your code or file. A colon where it shouldn't be. Post if you need some help finding it.
@TillmanTech2 жыл бұрын
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
@HollowsDarkness2 жыл бұрын
Then could you console.log(users.name) and it print out the ane of the users?
@AllThingsJavaScript2 жыл бұрын
Once you load the JSON file you can access it like any JavaScript object. So you could console.log any data it contains.
@HollowsDarkness2 жыл бұрын
@@AllThingsJavaScript gotcha then i must be doing something wrong lol, i can console.log the variable i attached the JSON to but if i try to do it grab the name or IDs from the variable it just comes back as undefined. I'll have to look more into it, thanks!
@AllThingsJavaScript2 жыл бұрын
@@HollowsDarkness If you need to, post your code.
@HollowsDarkness2 жыл бұрын
@@AllThingsJavaScript here is my code, import pokemon from './pokemon.json' assert {type: 'json'} let pokemonString = JSON.stringify(pokemon) let poke = [] // for (let p in pokemonString) { // poke.push(pokemonString) // } for (let i = 0; i < pokemonString.length; i++) { const p = pokemon[i]; poke.push(p) } console.log(poke)
@JIucmuk Жыл бұрын
thanks a lot!
@AllThingsJavaScript Жыл бұрын
Welcome!
@АлександрШтыб-е5т Жыл бұрын
Thank you very much! You helped me out
@AllThingsJavaScript Жыл бұрын
Glad I could help!
@frechdaXchs2 жыл бұрын
does not work for me. Need to access a local json file without a (live) server or user input. Seems impossible...
@AllThingsJavaScript2 жыл бұрын
For security reasons that is not allowed. A browser is not given access to files on your hard drive. As you can imagine there would be a lot of ways to use that against you.
@darkknight7623 Жыл бұрын
thank you sir, it helps a lot
@AllThingsJavaScript Жыл бұрын
Most welcome!
@roumen1669 Жыл бұрын
Thank you so much!
@AllThingsJavaScript Жыл бұрын
Glad it helped!
@angelgarcia69112 жыл бұрын
Thank you!
@EmelieBossАй бұрын
great!
@perdu0609 Жыл бұрын
Does anyone have an error "Cannot use import statement outside a module" ?
@AllThingsJavaScript Жыл бұрын
Did you set up your JavaScript file to be a module in your HTML file?
@fayyu55066 ай бұрын
this is still giving cors error
@AllThingsJavaScript6 ай бұрын
Do a google search on cors errors for localhost. There is a lot of information out there.
@MattiaRuberto Жыл бұрын
Mind-blowing!!!
@everestobot3934 Жыл бұрын
Local Filesystem Detected ! Put this to your header:
@avertry95292 жыл бұрын
Thanks, but your link to fetch, actually links to this video.
@AllThingsJavaScript2 жыл бұрын
Thanks for letting me know.
@mutamente Жыл бұрын
pouts!! que montagem huahuahuahuauha muito bom xD
@Assiel1 Жыл бұрын
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file///C:/XXX/app/js/app.json 🥲
@AllThingsJavaScript Жыл бұрын
What are you using for your local server? There may be documentation about disabling Same Origin Policy