Hey Rhys, if you are looking to parse output from mongosh programmatically, we are recommending to wrap the result with EJSON.stringify; for example:
$ /tmp/mongosh-1.0.1-linux-x64/bin/mongosh [...] --eval "EJSON.stringify(db.adminCommand('listDatabases'))"
Current Mongosh Log ID: 60fad826709a27c53c9cb992
Connecting to: mongodb+srv://<credentials>@[...]/
Using MongoDB: 4.4.7
Using Mongosh: 1.0.1
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
{"databases":[{"name":"test","sizeOnDisk":589824,"empty":false},{"name":"admin","sizeOnDisk":335872,"empty":false},{"name":"local","sizeOnDisk":3412008960,"empty":false}],"totalSize":3573481472,"ok":1,"$clusterTime":{"clusterTime":{"$timestamp":{"t":1627052073,"i":1}},"signature":{"hash":{"$binary":{"base64":"0YqoHxcwf2/Vv8T5c+aUOj+bXoM=","subType":"00"}},"keyId":6928827991380197000}},"operationTime":{"$timestamp":{"t":1627052073,"i":1}}}
That’s always programmatically parseable. And if you want something prettier/more human-friendly, you can use EJSON.stringify(result, null, ' '), while still maintaining machine readability.
Does this help you?