// JSON logging function
162163
func (l *intLogger) logJSON(t time.Time, level Level, msg string, args ...interface{}) {
	vals := l.jsonMapEntry(t, level, msg)
	args = append(l.implied, args...)

	if args != nil && len(args) > 0 {
		if len(args)%2 != 0 {
			cs, ok := args[len(args)-1].(CapturedStacktrace)
			if ok {
				args = args[:len(args)-1]
				vals["stacktrace"] = cs
			} else {
				args = append(args, "<unknown>")
			}
		}

		for i := 0; i < len(args); i = i + 2 {
			if _, ok := args[i].(string); !ok {
				// As this is the logging function not much we can do here
				// without injecting into logs...
				continue
			}
			val := args[i+1]
			switch sv := val.(type) {
			case error:
				// Check if val is of type error. If error type doesn't
				// implement json.Marshaler or encoding.TextMarshaler
				// then set val to err.Error() so that it gets marshaled
				switch sv.(type) {
				case json.Marshaler, encoding.TextMarshaler:
				default:
					val = sv.Error()
				}
			case Format:
				val = fmt.Sprintf(sv[0].(string), sv[1:]...)
			}

			vals[args[i].(string)] = val
		}
	}

	err := json.NewEncoder(l.writer).Encode(vals)
	if err != nil {
		if _, ok := err.(*json.UnsupportedTypeError); ok {
			plainVal := l.jsonMapEntry(t, level, msg)
			plainVal["@warn"] = errJsonUnsupportedTypeMsg

			json.NewEncoder(l.writer).Encode(plainVal)
		}
	}
}
1334596
func (n *DebugCapture) DumpJSON(data []byte, cpuPrefix string) {
	resp, err := n.getJSON(data, cpuPrefix)
	if err != nil {
		fmt.Println(fmt.Sprintf(`{"type":"debug_capture_error","message":%q}`, err.Error()))
		return
	}
	fmt.Println(resp)
}
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
}
478631
func (il IfLogger) WithJSON(values ...interface{}) ContextLogger {
	return il.With(values...).SetFormatter(jsonFormatter)
}
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)
}
1017879
func (r *Request) JSON(data interface{}) *Request {
	r.Use(body.JSON(data))
	return r
}
882961
func (lrt *LogRoundTripper) formatJSON(raw []byte) string {
	var rawData interface{}

	err := json.Unmarshal(raw, &rawData)
	if err != nil {
		log.Printf("[DEBUG] Unable to parse OpenStack JSON: %s", err)
		return string(raw)
	}

	data, ok := rawData.(map[string]interface{})
	if !ok {
		pretty, err := json.MarshalIndent(rawData, "", "  ")
		if err != nil {
			log.Printf("[DEBUG] Unable to re-marshal OpenStack JSON: %s", err)
			return string(raw)
		}

		return string(pretty)
	}

	// Mask known password fields
	if v, ok := data["auth"].(map[string]interface{}); ok {
		if v, ok := v["identity"].(map[string]interface{}); ok {
			if v, ok := v["password"].(map[string]interface{}); ok {
				if v, ok := v["user"].(map[string]interface{}); ok {
					v["password"] = "***"
				}
			}
			if v, ok := v["application_credential"].(map[string]interface{}); ok {
				v["secret"] = "***"
			}
			if v, ok := v["token"].(map[string]interface{}); ok {
				v["id"] = "***"
			}
		}
	}

	// Ignore the catalog
	if v, ok := data["token"].(map[string]interface{}); ok {
		if _, ok := v["catalog"]; ok {
			return ""
		}
	}

	pretty, err := json.MarshalIndent(data, "", "  ")
	if err != nil {
		log.Printf("[DEBUG] Unable to re-marshal OpenStack JSON: %s", err)
		return string(raw)
	}

	return string(pretty)
}
930199
func JSON(w io.Writer, x interface{}) error {
	encoder := json.NewEncoder(w)
	encoder.SetIndent("", "  ")
	return encoder.Encode(x)
}
797937
func JSON(val otto.Value) string {
	vm := otto.New()
	vm.Set("value", val)
	res, _ := vm.Run(`JSON.stringify(value)`)
	return res.String()
}
1339590
func NewJSONLogger(config *JSONLoggerConfig) (*JSONLogger, error) {
	if config == nil {
		return nil, errors.New("config cannot be nil")
	}

	l := &JSONLogger{
		config:      config,
		failedQueue: make([][]byte, 0),
	}
	return l, nil
}
109825
func (s Slice) JSONString(options ...DumperOptions) (string, error) {
	buf := &bytes.Buffer{}
	var opt *DumperOptions
	if len(options) > 0 {
		opt = &options[0]
	}
	d := NewDumper(buf, opt)
	if err := d.Append(s); err != nil {
		return "", WithStack(err)
	}
	return buf.String(), nil
}
1148361
func (t Version) JSON() (output string, err error) {
	var raw []byte
	ver := Get()
	if raw, err = json.MarshalIndent(ver, "", "\t"); err != nil {
		return
	}
	return string(raw), nil
}
1247573
func (u infoMessage) JSON() string {
	u.Status = "success"
	statusJSONBytes, e := json.MarshalIndent(u, "", " ")
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(statusJSONBytes)
}
108559
func jsonError(err error) string {
	var errMsg struct {
		Err string `json:"err"`
	}
	errMsg.Err = err.Error()

	data, _ := json.Marshal(&errMsg)
	return string(data)
}
1098364
func (j *Job) JSONString() (body string, err error) {
	err = j.Validate()
	if err != nil {
		return
	}

	bdy, err := json.MarshalIndent(j, "", "  ")
	body = string(bdy)

	return
}
650071
func Logging() HandlerFunc {
	return func(ctx *Context) {
		start := time.Now()
		p := ctx.Req().URL.Path
		if len(ctx.Req().URL.RawQuery) > 0 {
			p = p + "?" + ctx.Req().URL.RawQuery
		}

		ctx.Debug("Started", ctx.Req().Method, p, "for", ctx.IP())

		if action := ctx.Action(); action != nil {
			if l, ok := action.(LogInterface); ok {
				l.SetLogger(ctx.Logger)
			}
		}

		ctx.Next()

		if !ctx.Written() {
			if ctx.Result == nil {
				ctx.Result = NotFound()
			}
			ctx.HandleError()
		}

		statusCode := ctx.Status()

		if statusCode >= 200 && statusCode < 400 {
			ctx.Info(ctx.Req().Method, statusCode, time.Since(start), p)
		} else {
			ctx.Error(ctx.Req().Method, statusCode, time.Since(start), p, ctx.Result)
		}
	}
}
1001201
func (r rmMessage) JSON() string {
	msgBytes, e := json.MarshalIndent(r, "", " ")
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
	return string(msgBytes)
}