code: func NormalizeJSON(data string, obj bool) (string, error) {
  	buf := bytes.NewBufferString(data)
  	dec := json.NewDecoder(buf)
  	dec.UseNumber()
  	var decoded interface{}
  	if obj {
  		decoded = &map[string]interface{}{}
  	} else {
  		decoded = &[]interface{}{}
  	}
  	err := dec.Decode(decoded)
  	if err != nil {
  		return "", err
  	}
  	bufdat, err := ioutil.ReadAll(dec.Buffered())
  	if err != nil {
  		panic(err)
  	}
  	rest := strings.TrimSpace(string(bufdat) + buf.String())
  	if rest != "" {
  		return "", fmt.Errorf("got extra junk: %q", rest)
  	}
  
  	buf.Reset()
  	err = json.NewEncoder(buf).Encode(decoded)
  
  	// the TrimSpace chops off an extraneous newline that the json lib adds on.
  	return string(bytes.TrimSpace(buf.Bytes())), err
  }
docs: // NormalizeJSON is used to take some free-form JSON and validates that:
  //   * it only contains a valid JSON object (e.g. `{...stuff...}`); OR
  //   * it only contains a valid JSON array (e.g. `[...stuff...]`)
  //
  // If obj is true, this looks for an object, if it's false, it looks for an
  // array.
  //
  // This will also remove all extra whitespace and sort all objects by key.