// parseJSON handles parsing JSON output
323427
func parseJSON(input []byte) (*logEntry, error) {
	var raw map[string]interface{}
	entry := &logEntry{}

	err := json.Unmarshal(input, &raw)
	if err != nil {
		return nil, err
	}

	// Parse hclog-specific objects
	if v, ok := raw["@message"]; ok {
		entry.Message = v.(string)
		delete(raw, "@message")
	}

	if v, ok := raw["@level"]; ok {
		entry.Level = v.(string)
		delete(raw, "@level")
	}

	if v, ok := raw["@timestamp"]; ok {
		t, err := time.Parse("2006-01-02T15:04:05.000000Z07:00", v.(string))
		if err != nil {
			return nil, err
		}
		entry.Timestamp = t
		delete(raw, "@timestamp")
	}

	// Parse dynamic KV args from the hclog payload.
	for k, v := range raw {
		entry.KVPairs = append(entry.KVPairs, &logEntryKV{
			Key:   k,
			Value: v,
		})
	}

	return entry, nil
}
12588
func (r *Resp) ToJSON(v interface{}) error {
	data, err := r.ToBytes()
	if err != nil {
		return err
	}
	return json.Unmarshal(data, v)
}
854785
func PrintJSON(v interface{}) {
	body, err := json.MarshalIndent(v, "", "  ")
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s\n", body)
}
333651
func (n *DebugMsg) DumpJSON(cpuPrefix string) {
	fmt.Println(n.getJSON(cpuPrefix))
}
1185410
func ParsePkScript(pkScript []byte) (PkScript, error) {
	var outputScript PkScript
	scriptClass, _, _, err := ExtractPkScriptAddrs(
		pkScript, &chaincfg.MainNetParams,
	)
	if err != nil {
		return outputScript, fmt.Errorf("unable to parse script type: "+
			"%v", err)
	}

	if !isSupportedScriptType(scriptClass) {
		return outputScript, ErrUnsupportedScriptType
	}

	outputScript.class = scriptClass
	copy(outputScript.script[:], pkScript)

	return outputScript, nil
}
1333128
func DecodeJSON(r io.Reader) (interface{}, error) {
	decoder := json.NewDecoder(r)
	decoder.UseNumber()
	var doc interface{}
	if err := decoder.Decode(&doc); err != nil {
		return nil, err
	}
	if t, _ := decoder.Token(); t != nil {
		return nil, fmt.Errorf("invalid character %v after top-level value", t)
	}
	return doc, nil
}
968049
func (c Configuration) toJSON() (string, error) {
	c.setDefaults()
	jsonBytes, err := json.Marshal(c)
	if err != nil {
		return "", err
	}
	return string(jsonBytes), nil
}
765271
func ParseKeys(data map[string]interface{}, pairs [][]string) error {
	for _, args := range pairs {
		key, t := args[0], args[1]
		if err := ParseKey(data, key, t); err != nil {
			return err
		}
	}
	return nil
}
561977
func (ctxt *Context) ServeJSON(data interface{}) {
	encoded, err := json.Marshal(data)
	if err != nil {
		panic(err)
	}
	ctxt.Header().Set("Content-Type", "application/json")
	ctxt.Write(encoded)
}
284423
func ParseJSONFromString(json string, options ...ParserOptions) (Slice, error) {
	return ParseJSON(strings.NewReader(json), options...)
}
75358
func CleanseJSON(j []byte) ([]byte, error) {
	var m map[string]interface{}

	err := json.Unmarshal(j, &m)
	if err != nil {
		return nil, err
	}

	return json.Marshal(Cleanse(m))
}
1371853
func toJSON(v interface{}) string {
	b, err := json.Marshal(v)
	if err != nil {
		return err.Error()
	}
	return string(b)
}
273790
func DecodeJSON(res *http.Response, dest interface{}) error {
	defer CloseBody(res.Body)
	buf := getBuf()
	defer putBuf(buf)
	if err := json.NewDecoder(io.TeeReader(io.LimitReader(res.Body, 8<<20), buf)).Decode(dest); err != nil {
		return fmt.Errorf("httputil.DecodeJSON: %v, on input: %s", err, buf.Bytes())
	}
	return nil
}
1299016
func (r *Response) DecodeJSON(out interface{}) error {
	return jsonutil.DecodeJSONFromReader(r.Body, out)
}
541464
func ToJSON(p []byte, opts ToJSONOptions) ([]byte, error) {
	var yamlData interface{}
	if err := yaml.Unmarshal(p, &yamlData); err != nil {
		return nil, err
	}
	jsonData, err := toJSON(yamlData)
	if err != nil {
		return nil, err
	}
	if opts.Pretty {
		if opts.Indent != "" {
			return json.MarshalIndent(jsonData, "", opts.Indent)
		}
		return json.MarshalIndent(jsonData, "", defaultIndent)
	}
	return json.Marshal(jsonData)
}
279494
func (c *Client) ReadJSON(v interface{}) (err error) {
	_, r, err := c.NextReader()
	if err != nil {
		return err
	}
	return codec.NewDecoder(r, &jh).Decode(v)
}
511513
func RenderJSON(c *cli.Context) string {
	filePath := c.GlobalString("gossfile")
	varsFile := c.GlobalString("vars")
	debug = c.Bool("debug")
	TemplateFilter = NewTemplateFilter(varsFile)
	path := filepath.Dir(filePath)
	OutStoreFormat = getStoreFormatFromFileName(filePath)
	gossConfig := mergeJSONData(ReadJSON(filePath), 0, path)

	b, err := marshal(gossConfig)
	if err != nil {
		log.Fatalf("Error rendering: %v\n", err)
	}
	return string(b)
}