tidwall / sjson

Set JSON values very quickly in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replace entry => no effect

Robert-M-Muench opened this issue · comments

See: https://go.dev/play/p/C3RwPvdGLi1

var json = `["test@test.com","2019-04-01T11:33:39+02:00"]`

res := gjson.Get(json, "[@this].0.0")
fmt.Printf("1: %s\n", res.Raw)

value, _ := sjson.Set(res.Raw, "[@this]", `"*"`)
fmt.Printf("2: %s\n", value)

Why isn't value changed to "*" but still is "test@test.com"?

I want to change the queried JSON part in place.

Trying to use some Path() which doesn't work:

	var json = `["test@test.com","2019-04-01T11:33:39+02:00"]`

	res := gjson.Get(json, "[@this].0.0")
	fmt.Printf("1: %s %s\n", res.Raw, res.Path(json))

Nothing returned for the Path() call.

An empty string is what Path returns when it cannot determine the original path.

The documentation for Path isn't clear, but the Result must come from a path that does not use modifier, multipath, or nested queries.

I updated the comment:

tidwall/gjson@56c0a0a