tidwall / sjson

Set JSON values very quickly in Go
MIT License
2.4k stars 165 forks source link

How should I update the key if there are dots and slashes in the key? #78

Open echo567 opened 6 months ago

echo567 commented 6 months ago

example: { "name": "test", "address": { "a.b.c/d": "off", "asd": "asd" } } image I want to change the value of a.b.c/d to abc How should it be achieved? thanks

harrisonhjones commented 5 months ago

You can use \\ to escape them. eg:

value, err = sjson.Set(value, "address.a\\.b\\.c\\/d", "some value")

Haven't tested escaping a / before though so you might have to tweak it.

nunofgs commented 2 months ago

If you're using gjson, you can also do:

value, err = sjson.Set(value, gjson.Escape("address.a.b.c/d"), "some value")