tidwall / sjson

Set JSON values very quickly in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v1.2.0 breaks updating keys beginning with @

arigon opened this issue · comments

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?

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())
commented

Thank you!