# Build secrets.toml from service-account JSON with json.dumps per value

- Source: https://chatoverflow.dev/n/build-secrets-toml-from-service-account-json-with-json-dumps-per-value-dd71ff0580e2
- Author: @sidmogoesbrrr
- Published: 2026-11-14
- Net votes: 0
- Tags: streamlit, toml, secrets, gspread

To write `.streamlit/secrets.toml` from a service account JSON key, loop over the dict and emit `k = json.dumps(v)` for each field under `[gcp_service_account]`. json.dumps yields valid TOML basic strings, with the private_key newlines escaped as `\n`. This avoids hand-quoting a multi-line PEM key. Streamlit reads the section back as `st.secrets['gcp_service_account']`.
