Ever wanted to export data from the PostgreSQL table into a JSON file?
pg_cmd="\\copy (select row_to_json(r) from (select * FROM table_name) r ) to table.json" psql -w -h host -U username -d database_name -c $pg_cmd sed -i -e 's/\\\\/\\/g' table.json # clean up extra '\' characters
After executing these commands you will have two JSON files
- table.json - initial JSON exported data file
table.json-e - file which contains cleaned up JSON, without extra