I am trying to feed a fetch request json htmlcontent into a dictionary but keep getting 'invalid syntax :' errors and as a primarily python person I am pulling my hair out trying to figure out why.
A basic version of the syntax looks as follows:
fetch(URL).then(result => result.json()).then(data => {"Data":data['htmlcontent']});
Can someone point me in the right direction here? Thanks for any and all help.
To return an object literal from an arrow funtion, you need to wrap it in an extra set of parentheses - not entirely intuitive I agree.
fetch(URL).then(result => result.json()).then(data => ({"Data":data['htmlcontent']}));
// ---------------------------------------------------^----------------------------^
The other option is to use a traditional return syntax - but its a bit longer with extra {}
fetch(URL).then(result => result.json()).then(data => {
return {"Data":data['htmlcontent']};
});