1

I am using sjson in my golang project. I want to set some key-value pairs in my project. 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. Is there any prefix-posfix etc... How can i handle this problem?

Latif Uluman
  • 257
  • 3
  • 13

1 Answers1

1

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

    }
}
Latif Uluman
  • 257
  • 3
  • 13