psql with right query and right flag can do that.
$ psql -P pager -nqtc "select row_to_json(pg_database) from pg_database where datname = 'template0'" | jq
{
"datname": "template0",
...
"datacl": [
"=c/postgres",
"postgres=CTc/postgres"
]
}For example:
$ psql dbname -tAc 'SELECT json_agg(some_table) FROM some_table'
That will produce a valid JSON if you ever need to pipe it to another command. And I'm sure, psql will do the job a lot faster than node.By the way, you should not underestimate the built-in psql power and postgresql's json capability. Postgresql's JSON power rivals that of other JSON based No-SQL databases.