#How I can get String from an "json" URL?
23 messages · Page 1 of 1 (latest)
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
✅Marked as resolved by OP
What do you mean be “String”
Like the data when you put the link into a browser?
First, you will need to fetch the site. Which’ll return the json
await fetch(url)
Will fetch it
i want to get an string from this website ((https://api.laut.fm/station/synradiode/current_song) )
Secondly, you’ll need to use the method .json(), which will return a promise of the json the site returns
If you give that a go and come back with any issues, I can help
await fetch("https://api.laut.fm/station/synradiode/current_song").json();
like that?
.json() is also a promise. So try wrapping either your fetch in a function, or just attach your fetch to a variable first, which I would say to do
const d = await fetch(url)
then if(d.ok) {
const json = await d.json()
}
The ok property just shows if the request was successful
hmm? I do not really understand what exactly you mean but like this?
const url = await fetch("https://api.laut.fm/station/synradiode/current_song");
if(url.ok) {
var RadioData = await url.json
}
console.log(RadioData.title);
json() is a method. Don’t use var, use let or const and make sure you’re in the same scope

const url = await fetch("https://api.laut.fm/station/synradiode/current_song");
if(url.ok) {
let json = await url.json
console.log(json.title);
}
.json() is a method
where should i place this method
.json() not .json
It’s a method, not a property
omg
nvm
Thanks for you help 