DEV Community

Dino for Wizard Health

Posted on

5 2

Meza: From PostgreSQL table to a JSON file

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

Enter fullscreen mode Exit fullscreen mode

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

โœŒ๏ธ

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where youโ€™ll build it, break it, debug it, and fix it. Youโ€™ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good olโ€™ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. โค๏ธ