// JSON sends "data" as a JSON HTTP response
775171
func (s *Server) JSON(w http.ResponseWriter, status int, data interface{}) {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(status)
	json.NewEncoder(w).Encode(data)
}
619434
func (s shareMesssage) JSON() string {
	s.Status = "success"
	shareMessageBytes, e := json.MarshalIndent(s, "", " ")
	fatalIf(probe.NewError(e), "Failed to marshal into JSON.")

	// JSON encoding escapes ampersand into its unicode character
	// which is not usable directly for share and fails with cloud
	// storage. convert them back so that they are usable.
	shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u0026"), []byte("&"), -1)
	shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u003c"), []byte("<"), -1)
	shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u003e"), []byte(">"), -1)

	return string(shareMessageBytes)
}
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
}
657480
func (o DepAnalysisOutput) JSON(w io.Writer) error {
	o.sort()
	return JSON(w, o)
}
228908
func (h *Http) PostJson(urlStr string, body interface{}, target interface{}) (error, int) {
	bodyBytes, err := json.Marshal(body)
	if err != nil {
		return err, -1
	}

	req := &http.Request{
		Method: "POST",
		Header: map[string][]string{
			"Content-Type": {"application/json"},
		},
		Body: ioutil.NopCloser(bytes.NewReader(bodyBytes)),
		ContentLength: int64(len(bodyBytes)),
	}

	resp, err := h.executeRequest(urlStr, req)
	if err != nil {
		return err, -1
	}

	defer resp.Body.Close()
	jsonData, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err, -1
	}

	logResponse(urlStr, resp, jsonData)

	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		return errors.New(fmt.Sprintf("Expected code %s but got %d,\n response: [%s]",
			"20x", resp.StatusCode, string(jsonData))), resp.StatusCode
	}

	if target != nil {
		err = json.Unmarshal(jsonData, target)
		if err != nil {
			return err, resp.StatusCode
		}
	}

	return nil, resp.StatusCode
}
672396
func (ctx *Context) JSON(obj interface{}) *Context {
	data, err := json.Marshal(obj)
	if err == nil {
		fmt.Fprint(ctx.Writer(), string(data))
	}
	return ctx
}
766317
func (s stopHealMessage) JSON() string {
	stopHealJSONBytes, e := json.MarshalIndent(s, "", " ")
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(stopHealJSONBytes)
}
930199
func JSON(w io.Writer, x interface{}) error {
	encoder := json.NewEncoder(w)
	encoder.SetIndent("", "  ")
	return encoder.Encode(x)
}
877458
func (s *Socket) SendJSON(data interface{}) (err error) {
	w, err := s.NextWriter(websocket.TextMessage)
	if err != nil {
		return err
	}
	if data != nil {
		codec.NewEncoder(w, &jh).Encode(data)
	}
	return w.Close()
}
1185940
func (r *Response) WriteJson(value interface{}, contentType string) error {
	return writeJSON(r, http.StatusOK, contentType, value)
}
141047
func (wc *WebhookContext) JSON(out interface{}) error {
	var err error
	if wc.body == nil {
		wc.firstParse = true
		wc.body, err = ioutil.ReadAll(wc.gin.Request.Body)

		if err != nil {
			return err
		}
	}
	err = json.Unmarshal(wc.body, out)

	if err != nil && strings.HasPrefix(string(wc.body), "payload=") {
		s := string(wc.body)
		s, err = uurl.QueryUnescape(s[8:])
		if err != nil {
			return err
		}
		err = json.Unmarshal([]byte(s), out)

	}
	return err
}
675671
func (c *xContext) JSON(i interface{}, codes ...int) (err error) {
	var b []byte
	if c.echo.Debug() {
		b, err = json.MarshalIndent(i, "", "  ")
	} else {
		b, err = json.Marshal(i)
	}
	if err != nil {
		return err
	}
	return c.JSONBlob(b, codes...)
}
978109
func JSON(w http.ResponseWriter, responses ...interface{}) {
	respond := func(payload interface{}) {
		var result []byte
		var err error
		encode := func(payload interface{}) ([]byte, error) {
			if config.Pretty {
				return json.MarshalIndent(payload, "", "\t")
			}
			return json.Marshal(payload)
		}
		switch value := payload.(type) {
		case []byte:
			result = value
		case error:
			// main key is "error"
			errWithStack := errors.WithStack(value)
			if config.Logger != nil {
				config.Logger(errWithStack)
			}
			result, err = encode(errorResponse(errWithStack))
		case successMessage:
			// main key is "success"
			result, err = encode(value)
		default:
			// main key is "response"
			result, err = encode(struct {
				Response interface{} `json:"response"`
			}{value})
		}
		if err != nil {
			result, _ = encode(errorResponse(errors.WithStack(err)))
		}
		w.Header().Set("Content-Type", "application/json")
		w.Write(result)
	}

	for _, response := range responses {
		switch value := response.(type) {
		case nil:
			// this will match a nil error
			continue
		case func() ([]byte, error):
			result, err := value()
			JSON(w, err, result)
		case func() (interface{}, error):
			result, err := value()
			JSON(w, err, result)
		case func() error:
			err := value()
			if err == nil {
				continue
			}
			respond(err)
		case *error:
			if *value == nil {
				continue
			}
			respond(*value)
		case error:
			respond(value)
		case string:
			if value == "" {
				continue
			}
			respond(value)
		case bool:
			if !value {
				continue
			}
			respond(value)
		case successMessage:
			respond(value)
		default:
			respond(value)
		}
		// Exit on the first output...
		return
	}
	respond(false)
}
532392
func (ctx *Context) JSON(obj interface{}) {
	json, err := json.Marshal(obj)
	if err != nil {
		panic(err)
	}
	ctx.SetHeader("Content-Type", "application/json")
	ctx.Send(json)
}
1073314
func (r *SubRouter) JSON(route string, handler interface{}) *SubRouter {
	route = r.prefixedRoute(route)
	if r.parent != nil {
		h := r.parent.determineHandler(handler)
		r.parent.handleReg(MethodGET, route, jsonHandler(h), r.prefixes)
	}

	return r
}
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)
}
1246707
func (d *Dataset) JSON() (*Exportable, error) {
	back := d.Dict()

	b, err := json.Marshal(back)
	if err != nil {
		return nil, err
	}
	return newExportableFromBytes(b), nil
}