question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exporting CSV (or markdown) exports jsonb as `[object Object]`

See original GitHub issue

Bug report

Describe the bug

Exporting rows from a table with jsonb columns, exports those as a JavaScript [object Object]

To Reproduce

  1. Go to https://app.supabase.com/project/<your project id>/sql (The “Sql query” tab in your project dashboard).
  2. Click on “New Query” and enter select * from auth.users;
  3. Run the query
  4. Notice how the raw_app_metadata shows up as a nice json string in the table (expected behavior)
  5. Click on the “Results” dropdown and click “Download CSV”.
  6. Inspect the csv and notice how raw_app_metadata shows [Object object] instead of the actual metadata (not expected)

Expected behavior

The exported csv would show the same json string that the ui does

System information

  • Browser: Firefox

Additional context

Also a problem with the markdown exporter

Previously reported here https://github.com/supabase/supabase/issues/1764

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
masa5714commented, Dec 11, 2022

[ For those who want CSV immediately ]


The following method solved the problem.

Example:

  • Table Name -> all_patterns
  • Column Name -> shipping_fee_patterns
select REGEXP_REPLACE(REGEXP_REPLACE(jsonb_pretty(shipping_fee_patterns), '\r|\n|\r\n| ', '','g'), '"', '""', 'g') as shipping_fee_patterns from all_patterns;

Please let me know if there is a smarter way to write this.


I would wait for a fundamental solution. But if you want CSV immediately, try this method.

In my case, I had the same problem with the JSON type. Sorry if this is not helpful since it is not jsonb.

Before :

0e3fcb72cc0f39ee3e2b57c9d4db2d28

After :

7f557ed00be28739fee1b292c6c017ce

1reaction
j4w8ncommented, Dec 4, 2022

@Gautam-Arora24

You are welcome to submit a PR. I don’t have any repo powers; I’m just a contributor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exporting CSV exports jsonb as [object Object] #1764 - GitHub
Select rows from a table with jsonb · Click Export CSV ...
Read more >
Export JSON to CSV file using Javascript (in the browser)
Call the“exportCSVFile(headers, itemsFormatted, fileTitle)” function and insert your own “headers”, “itemsFormatted” and “fileTitle” variables.
Read more >
Small JavaScript Library To Export JSON Data To CSV File
CSV -Export is a small and easy-to-use JavaScript library which lets you export JSON data to a CSV file.
Read more >
Object to CSV format and Export in JavaScript - Stack Overflow
The problem is not in the part you have shown us, but in the actual downloadCSV function that is only contained in your...
Read more >
Serialize and Deserialize objects to JSON (or whatever) format |
Serialize.Template class, it'll be relatively easy to adapt it to have a pre-compiled export/import methods to export/import data in whatever ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found