title: How to read a text file line-by-line in Go when some lines are long enough to cause "bufio.Scanner: token too long" errors?
body: <p>I have a text file where each line represents a JSON object.  I am processing this file in Go with a simple <code>for</code> loop like this:</p>
  
  <pre><code>scanner := bufio.NewScanner(file)
  for scanner.Scan() {
     jsonBytes = scanner.Bytes()
     var jsonObject interface{}
     err := json.Unmarshal(jsonBytes, &amp;jsonObject)
  
     // do stuff with "jsonObject"...
  
  }
  if err := scanner.Err(); err != nil {
     log.Fatal(err)
  }
  </code></pre>
  
  <p>When this code reaches a line with a particularly large JSON string (~67kb), I get the error message, "bufio.Scanner: token too long".</p>
  
  <p>Is there an easy way to increase the max line size readable by <code>NewScanner</code>?  Or is there another approach you can take altogether, when needing to read lines that are too large for <code>NewScanner</code> but are known to not be of unsafe size generally?</p>