How to generate JSON with random password with pwgen and bash

This script will generate a random password stored in a JSON file:

echo "{\"secret\": \"$(pwgen 30 1)\"}" > secret.json

Example output

{"secret": "thie2uv6Ro3cah2oodohx2vai5Ahka"}