Wizard Health profile image Wizard Health

Meza: From PostgreSQL table to a JSON file

twitter logo github logo ・1 min read

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

  1. table.json - initial JSON exported data file
  2. table.json-e - file which contains cleaned up JSON, without extra \ characters

✌️

twitter logo DISCUSS
Building a better healthcare for the patients and the doctors.
Classic DEV Post from Feb 10

Is Haskell bad for FP?

Wizard Health profile image
Building a better healthcare.

Still don't have a dev.to account? You're welcome to lurk, but it's better to be part of the community.

Sign up now ❤️