2

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.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
j.t.2.4.6
  • 178
  • 1
  • 11

1 Answers1

0

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']};
});
Jamiec
  • 133,658
  • 13
  • 134
  • 193