tidwall / sjson

Set JSON values very quickly in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If we dont know the full path, how we specify it?

latifuluman opened this issue · comments

I have an unstructured dynamic object. So I can not know the path. It is like following:
{

	"temp1": {
		"temp2": {
			"password": "123456",
			"country": "turkey",
			"temp3": {
				"password": "789654"
			}
		}
	}
}

I want to edit password values to "secret", but in my program I dont know the path. Can I use prefix-posfix etc... How can i handle this problem?

I solved it without using sjson, but using recursive function like following:

func changePassword(myMap map[string]interface{}) {
    for key, value := range myMap {
        if key == "password" {
            myMap [key] = "******"
        }
        if _, ok := value.(map[string]interface{}); ok {
            changePassword(value.(map[string]interface{}))
        }

    }
}