// ReadJson will parses the JSON-encoded data in the http
// Request object and stores the result in the value
// pointed to by v.
498637
func ReadJson(r *http.Request, v interface{}) error {
	body, err := ioutil.ReadAll(r.Body)
	r.Body.Close()
	if err != nil {
		return err
	}
	return json.Unmarshal(body, v)
}
1278327
func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(code)
	buf, err := json.MarshalIndent(v, "", "  ")
	if err != nil {
		return err
	}
	if _, err := w.Write(buf); err != nil {
		return err
	}
	return nil
	//return json.NewEncoder(w).Encode(v)
}
1223432
func SendJson(w http.ResponseWriter, i interface{}) error {
	var buf bytes.Buffer
	enc := json.NewEncoder(&buf)
	if err := enc.Encode(i); err != nil {
		http.Error(w, fmt.Sprintf("unable to encode: %v", err), http.StatusInternalServerError)
		log.Printf("[SENDJSON] unable to encode json output in SendUserDetails: %v", err)
		return err
	}
	count := 0
	for count < buf.Len() {
		w, err := w.Write(buf.Bytes()[count:])
		if err != nil {
			log.Printf("[SENDJSON] failed to write: %v", err)
			return err
		}
		count += w
	}
	return nil
}
1189504
func (c *Client) NewJSONRequest(method string, url string, data interface{}) (*http.Request, error) {
	var reader io.Reader
	if data != nil {
		b, err := json.Marshal(data)
		if err != nil {
			return nil, err
		}
		reader = bytes.NewReader(b)
	}
	req, err := http.NewRequest(method, fmt.Sprintf("%s/%s", strings.TrimRight(c.Url, "/"), strings.TrimLeft(url, "/")), reader)
	if err != nil {
		return nil, err
	}
	if data != nil {
		req.Header.Set("Content-Type", "application/json")
	}
	req.Header.Set("X-Api-Key", c.Key)
	return req, nil
}
556499
func ReadJSON(fs filesystem.Filespace, src string, object interface{}) error {
	jsonb, err := fs.ReadFile(src)
	if err != nil {
		return err
	}
	return varutil.ObjectFromJSON(object, string(jsonb))
}
989111
func (r *Response) Json(obj interface{}) error {
	res, err := json.Marshal(obj)
	if err != nil {
		return err
	}

	r.writer.Header().Set("Content-Type", "application/json")
	return r.Raw(res)
}
1368937
func (c *Client) PutJSON(p string, i interface{}, ro *RequestOptions) (*http.Response, error) {
	return c.RequestJSON("PUT", p, i, ro)
}
457210
func sendJSON(code int, resp interface{}, w http.ResponseWriter, r *http.Request) error {
	data, err := json.Marshal(resp)
	if err != nil {
		return err
	}
	writeResponse(w, code, data)
	return nil
}
351469
func fetchJSON(c context.Context, client *http.Client, val interface{}, f func() (*http.Request, error)) error {
	r, err := f()
	if err != nil {
		logging.Errorf(c, "auth: URL fetch failed - %s", err)
		return err
	}
	logging.Infof(c, "auth: %s %s", r.Method, r.URL)
	resp, err := ctxhttp.Do(c, client, r)
	if err != nil {
		logging.Errorf(c, "auth: URL fetch failed, can't connect - %s", err)
		return transient.Tag.Apply(err)
	}
	defer func() {
		ioutil.ReadAll(resp.Body)
		resp.Body.Close()
	}()
	if resp.StatusCode >= 300 {
		body, _ := ioutil.ReadAll(resp.Body)
		// Opportunistically try to unmarshal the response. Works with JSON APIs.
		if val != nil {
			json.Unmarshal(body, val)
		}
		logging.Errorf(c, "auth: URL fetch failed - HTTP %d - %s", resp.StatusCode, string(body))
		err := fmt.Errorf("auth: HTTP code (%d) when fetching %s", resp.StatusCode, r.URL)
		if resp.StatusCode >= 500 {
			return transient.Tag.Apply(err)
		}
		return err
	}
	if val != nil {
		if err = json.NewDecoder(resp.Body).Decode(val); err != nil {
			logging.Errorf(c, "auth: URL fetch failed, bad JSON - %s", err)
			return fmt.Errorf("auth: can't deserialize JSON at %q - %s", r.URL, err)
		}
	}
	return nil
}
863638
func (e Response) JSON(decoder interface{}) (*interface{}, error) {
	defer e.Res.Body.Close()
	resp := &decoder
	err := json.NewDecoder(e.Res.Body).Decode(resp)
	return resp, err
}
984327
func (ctx *context) ReadJSON(jsonObject interface{}) error {
	var unmarshaler = json.Unmarshal
	if ctx.shouldOptimize() {
		unmarshaler = jsoniter.Unmarshal
	}
	return ctx.UnmarshalBody(jsonObject, UnmarshalerFunc(unmarshaler))
}
659266
func (c *Client) GetJSON(ctx context.Context, url string, data interface{}) error {
	if !strings.HasPrefix(url, c.discoRoot()) {
		return fmt.Errorf("wrong URL (%q) for this server", url)
	}
	hreq := c.newRequest(ctx, "GET", url)
	resp, err := c.expect2XX(hreq)
	if err != nil {
		return err
	}
	return httputil.DecodeJSON(resp, data)
}
180084
func WriteJSON(w http.ResponseWriter, value interface{}, status int) error {
	return jsonResponseEncoder.writeResponseJSON(w, value, status)
}
39447
func (decoder *JSONTraceDecoderV1) Read(ctx context.Context, req *http.Request) error {
	var input signalfxformat.InputSpanList
	if err := easyjson.UnmarshalFromReader(req.Body, &input); err != nil {
		return errInvalidJSONTraceFormat
	}

	if len(input) == 0 {
		return nil
	}

	spans := make([]*trace.Span, 0, len(input))

	// Don't let an error converting one set of spans prevent other valid spans
	// in the same request from being rejected.
	var conversionErrs *traceErrs
	for _, is := range input {
		inputSpan := (*InputSpan)(is)
		if inputSpan.isDefinitelyZipkinV2() {
			s, err := inputSpan.fromZipkinV2()
			is.Span.Timestamp = signalfxformat.GetPointerToInt64(inputSpan.Timestamp)
			is.Span.Duration = signalfxformat.GetPointerToInt64(inputSpan.Duration)
			if err != nil {
				conversionErrs = conversionErrs.Append(err)
				continue
			}

			spans = append(spans, s)
		} else {
			derived, err := inputSpan.fromZipkinV1()
			if err != nil {
				conversionErrs = conversionErrs.Append(err)
				continue
			}

			// Zipkin v1 spans can map to multiple spans in Zipkin v2
			spans = append(spans, derived...)
		}
	}

	err := decoder.Sink.AddSpans(ctx, spans)
	return conversionErrs.ToError(err)
}
845993
func (f *Request) Json(j interface{}) *Request {
	f.json = j
	f.jsonIsSet = true
	f.SetHeader("Content-type", "application/json")
	return f
}
297551
func (c *C) ParseJSON(v interface{}) {
	defer c.Request.Body.Close()
	c.Panic(json.NewDecoder(c.Request.Body).Decode(v))
}
197296
func (b *HttpRequest) ToJson(v interface{}) error {
	data, err := b.Bytes()
	if err != nil {
		return err
	}
	return json.Unmarshal(data, v)
}