I am trying to store array of objects in secret manager, but it always throws error when I click on "Key/Value" in secret manager, the error is The secret value can't be converted to key name and value pairs.
.
The value I would like to store in secret manager is "Users" : [{"username":"User1"},{"username":"User2"}]
2
Answers
Solution 1:
If you want to save it as a Plaintext, try the following:
Solution 2:
If you want to save it as key/value pairs, use the following:
Solution 3:
If you want to save it as key/value pairs and don’t want to change the format, use the following:
Conclusion:
You cannot convert a JSON object to a key/value pair if it is an array. You have to change the format as key/value pair is a list of key-with-value (e.g.,
"key": "value"
) pairs. If you want it to be an array then store it as plaintext and retrieve it as a string and then convert it to JSON and use it accordingly. Or, you can haveUsers
as key and the array as value which is a JSON string. Again, you need to retrieve it as a string and then convert it to JSON and use it accordingly but this time it is a key/value pair and not plaintext.Don’t click Key/Value.
Instead, use Plaintext and extract the individual values in your program by converting the string to JSON (
json.loads()
) and referencing the individual elements.For example: