code: func (p *Process) doJSON(method, path string, req, resp interface{}) error {
  	// Encode request.
  	var r io.Reader
  	if req != nil {
  		buf, err := json.Marshal(req)
  		if err != nil {
  			return err
  		}
  		r = bytes.NewReader(buf)
  	}
  
  	// Create request.
  	httpRequest, err := http.NewRequest(method, p.URL()+path, r)
  	if err != nil {
  		return err
  	}
  
  	// Send request.
  	httpResponse, err := http.DefaultClient.Do(httpRequest)
  	if err != nil {
  		return err
  	}
  	defer httpResponse.Body.Close()
  
  	// Read response body.
  	body, err := ioutil.ReadAll(httpResponse.Body)
  	if err != nil {
  		return err
  	}
  
  	// Check response code.
  	if httpResponse.StatusCode == http.StatusNotFound {
  		return fmt.Errorf("not found: %s", path)
  	}
  
  	// If an error was returned then return it.
  	var errResp errorResponse
  	if err := json.Unmarshal(body, &errResp); err != nil {
  		return errors.New("phantomjs.Process: " + string(body))
  	} else if errResp.Error != "" {
  		return errors.New(errResp.Error)
  	}
  
  	// Decode response if reference passed in.
  	if resp != nil {
  		if err := json.Unmarshal(body, resp); err != nil {
  			return fmt.Errorf("unmarshal error: err=%s, body=%s", err, body)
  		}
  	}
  
  	return nil
  }
docs: // doJSON sends an HTTP request to url and encodes and decodes the req/resp as JSON.