This zone is sleeping right now! ZzzZZzzz

Better not distrub it! ~You go to the petrol station and buy a slushy instead, everything is cool!~

This area will open again in 000.beats!

(Learn about Swatch Time)

Some other zones are awake :^]


Chat Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
May 11, 2026 - @341.01 (what is this?)
Activity rating: Three Stars Posts & Arts: 38/1k.beats Random | Recent Posts | Guild Recents
News: :4u: ~~~~~~~~~~~  :4u: Guild Events: Spring Themed Projects

+  MelonLand Forum
|-+  Life & The Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  How to fetch values from a JSON file with JS?


« previous next »
Pages: [1] Print Embed
Author Topic: How to fetch values from a JSON file with JS?  (Read 733 times)
asterhalloween
Casual Poster ⚓︎
*
View Profile WWW


the beauty of experiencing the world
⛺︎ My Room
SpaceHey: Friend Me!
iMood: mythicalwaters

Artifacts:
First 1000 Members!Joined 2023!
« on: October 12, 2024 @826.04 » Embed

Hello, everybody! I'm looking for a bit of help on how to do this thing because honestly I don't really know much about JavaScript (like almost nothing actually. dont let my yapping fool you) and as much messing around I've been doing I haven't been able to figure this out.

So, I want to create a Webring where people have little pixel bugs to help the ecosystem of their website. I'm using onionring as a base but for the widget I want to be able to automatically display the user's bug image as well as its name. A similar Webring I've seen is the jellyworld webring, which uses a JSON file to store the Webring members and their name, jelly, etc. and it puts it on the widget automatically by fetching the values based off of the url. It runs a bit different than the onionring system and so there are a few conflicting things with the system, but I don't particularly see why it wouldn't be possible to adapt onionring to do something similar, I just don't know how I would go about doing that.

I'm going to link the relevant files below, I haven't changed it much from the base template but thats because I removed all my attempts at getting it to work before because it kinda.. broke the whole thing :drat:

https://asterhalloween.neocities.org/buggyfriends/onionring-widget.js <- the thing that makes the widget and ideally would fetch from the json file
https://asterhalloween.neocities.org/buggyfriends/buggyfriends.json <- the json file
https://asterhalloween.neocities.org/buggyfriends/onionring-variables.js <- currently is what contains the urls. but i also yoinked the const so it gets the json
https://asterhalloween.neocities.org/buggyfriends/onionring-index.js <- I dont know if this will be useful at all for figuring this out but im linking it just incase ok
Logged

:4u: Love makes the world go round! :transport:
candycanearter07
Hero Member ⚓︎
*****
View Profile WWWArt


i like slimes
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: candycanearter
Itch.io: My Games
RSS: RSS

Guild Memberships:
Artifacts:
it's tbhchansey!Goomy, I Choose You!Suck At Something September - Did It!uh oh! a pigeon got in!Artsy Candy Cane
« Reply #1 on: October 15, 2024 @104.99 » Embed

Looking it up, its actually really simple! fetch() has a special thing to parse JSON data to an object, and the fetch syntax is pretty easy. the only caveot is you need to define the function its in as an async function, or it will yell at you.

Code
async function funcNamewhatever() {
  let res = await fetch("yoursite.com/assets/whatever/file.json");
  if (!res.ok)
    { throw new Error(`HTTP Error while getting file: ${res.status}`); }

  let json = await res.json();
  return json;
}

also, the webring sounds super cute and i want to join :D
Logged

new to oldnet be nice
https://status.cafe/users/candycanearter/badge.png https://abslimeware.neocities.org/assets/images/blinkers/penguins.gif

https://abslimeware.neocities.org/assets/images/blinkers/slimebounce.gif https://card.exophase.com/2/0/268504.png?1727352149

https://i.imgur.com/S1cx8ZZ.pnghttps://i.imgur.com/7ntZZGM.pnghttps://i.imgur.com/xKIpW2A.pnghttps://i.imgur.com/YMPbu9R.png

Artifact Swap: charry zardshoeDS Lover (replacement)Ball Creaturecards all the way down
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | ~ Send Feedback ~ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi

MelonLand Nav

@000

Want to Login or Join ?

Minecraft: Online
Join: craft.melonking.net