sjson icon indicating copy to clipboard operation
sjson copied to clipboard

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

Open echo567 opened this issue 1 year ago • 2 comments

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

echo567 avatar Mar 02 '24 11:03 echo567

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.

harrisonhjones avatar Apr 04 '24 18:04 harrisonhjones

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

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

nunofgs avatar Jul 05 '24 16:07 nunofgs