JSON to Variable
Get JSON from a URL and set a variable to a specific value in the JSON.
Context: I want to be able to get the name of a hex color code from "https://www.thecolorapi.com/id?hex=ffffff".
36 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I am very unexperienced and have no clue what that means 😅
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Oh I see, yes I am building this in a cloudflare worker.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Awesome, thanks!
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yes, I have seen it but how to a get a specific piece of the json and not the whole thing?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I want: "value":"White"
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ohhhh i see, wow that is pretty straight forward
ok i will try to use it now, one sec
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
kk
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Coolio, I will try it out now. Thanks!
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
So here is my code that I have adopted into my base project:
And it is throwing an 500 Internal Server Error
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yeah my syntax is crazy, i have other if statements with it to act as pages on the api
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yes kinda, I want to add other data as well
Also I am sure you know but just to make sure the URL would be more like https://worker.url/?type=color&hex=FFFFFF
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
kk
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Perfect! Thank you for all your help. I will try incorporating this now.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I am sorry but I need a little more help xD, I am struggling to incorporate the code into my project so here is my project thus far with my attempt of incorporating them
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oh sorry no I am getting:
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
all good, i might be a bit as well
thank you again for all your help
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Works like a charm, thank you! This is helping me get better at JS and JSON.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View