Can an object be stored as an environment variable? Returns undefined

I need to create environment variables to store secrets like database credentials. I created an object like such as an environment variable:
Key = mysecrets
Value = ({mysql:{host:‘a’,
port:‘b’,
user:‘c’,
pass:‘d’},
token:‘123’})

I access the variable using process.env.mysecrets.
Printing the entire object works, but printing any key/value pair within returns undefined.

Figured it out. It must be stored as a JSON object and then parsed in the code. Using JSON.parse(mysecrets) allowed me to access subobjects.