v1.2.0 breaks updating keys beginning with @
arigon opened this issue · comments
Alex commented
Hello
version 1.2.0+ which added "updates of complex paths" breaks updating keys beginning with the @ symbol.
Example:
data, err := sjson.SetBytes([]byte(`{"Test":123}`), "@timestamp", time.Now().Unix())
if err != nil {
log.Fatal(err)
}
Current Result:
{"Test":123}
Expected:
{"Test":123,"@timestamp":1639152890}
Is there a workaround?
Josh Baker commented
Hi,
The @
symbol is one of the reserved character. The workaround is to escape it with a \
character.
// Using either one of these styles
sjson.SetBytes([]byte(`{"Test":123}`), "\\@timestamp", time.Now().Unix())
sjson.SetBytes([]byte(`{"Test":123}`), `\@timestamp`, time.Now().Unix())
Alex commented
Thank you!