tidwall / sjson

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

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

Closed latifuluman closed 4 years ago

latifuluman commented 4 years ago

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?

latifuluman commented 4 years ago

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{}))
        }

    }
}