MCPcopy
hub / github.com/tidwall/sjson / SetOptions

Function SetOptions

sjson.go:631–647  ·  view source on GitHub ↗

SetOptions sets a json value for the specified path with options. A path is in dot syntax, such as "name.last" or "age". This function expects that the json is well-formed, and does not validate. Invalid json will not panic, but it may return back unexpected results. An error is returned if the path

(json, path string, value interface{},
	opts *Options)

Source from the content-addressed store, hash-verified

629// Invalid json will not panic, but it may return back unexpected results.
630// An error is returned if the path is not valid.
631func SetOptions(json, path string, value interface{},
632 opts *Options) (string, error) {
633 if opts != nil {
634 if opts.ReplaceInPlace {
635 // it's not safe to replace bytes in-place for strings
636 // copy the Options and set options.ReplaceInPlace to false.
637 nopts := *opts
638 opts = &nopts
639 opts.ReplaceInPlace = false
640 }
641 }
642 jsonh := *(*stringHeader)(unsafe.Pointer(&json))
643 jsonbh := sliceHeader{data: jsonh.data, len: jsonh.len, cap: jsonh.len}
644 jsonb := *(*[]byte)(unsafe.Pointer(&jsonbh))
645 res, err := SetBytesOptions(jsonb, path, value, opts)
646 return string(res), err
647}
648
649// SetBytesOptions sets a json value for the specified path with options.
650// If working with bytes, this method preferred over

Callers 1

SetFunction · 0.85

Calls 1

SetBytesOptionsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…