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)
| 629 | // Invalid json will not panic, but it may return back unexpected results. |
| 630 | // An error is returned if the path is not valid. |
| 631 | func 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 |
no test coverage detected
searching dependent graphs…