1

I am working on a xml parser which gets xml response from RSS feeds I happened to read some posts on json.Decode VS json.Unmarshal How to get JSON response from http.Get. In short:

  1. when data source is http.get which is streams we should use json.decoder, as it might be a very long json
  2. if response body is small enough, we can read it all into memory with ioutil.ReadAll and use json.Unmarshal. Also , json.Unmarshal is dealing with byte/string not stream

So I have the same question to xml decoding , does the same rule apply to http's xml response data ? Which means I should use xml.decode to parse http.get response , rather than ioutil.ReadAll and xml.Unmarshal ?

Jia
  • 2,417
  • 1
  • 15
  • 25
  • how big is this "very long json"? – Vinicius Cardoso May 17 '22 at 13:33
  • @ViniciusCardoso Here is one json file with 20 articles, size is 1.1M. (-rw-rw-r-- 1 jia jia 1.1M May 21 10:15 nytimes-size.json) is it a very 'big' file for my solution above ? The size might increase if I want to retrieve more articles by increasing the url parameters. Any suggestions on a better solution ;) – Jia May 21 '22 at 02:18

0 Answers0