skip to Main Content

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"}]

enter image description here

enter image description here

2

Answers


  1. Solution 1:

    If you want to save it as a Plaintext, try the following:

    {
      "Users": [
        {"username": "User1"},
        {"username": "User2"}
      ]
    }
    

    Solution 2:

    If you want to save it as key/value pairs, use the following:

    {
        "username1": "User1",
        "username2": "User2"
    }
    

    Solution 3:

    If you want to save it as key/value pairs and don’t want to change the format, use the following:

    {
      "Users": "[{"username": "User1"},{"username": "User2"}]"
    }
    

    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 have Users 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.

    Login or Signup to reply.
  2. 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:

    object['Users'][0]['username']
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search