Giter Club home page Giter Club logo

json-to-csv-export's Introduction

coston

json-to-csv-export's People

Contributors

coston avatar dependabot[bot] avatar dnim avatar galdil avatar isker avatar orzechowskid avatar sabril avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

json-to-csv-export's Issues

doesn't work when strings contain double-quotation marks

when I try this snippet in the live demo at https://json-to-csv-export.coston.io/ :

  <button onClick={() => csvDownload({ delimiter: ',', data: [{ foo: '"hello"', bar: '"there"' }] })}>
    Download Data
  </button>

I receive this .csv file:

foo,bar
"\"hello\"","\"there\""

I expected to receive this .csv file:

foo,bar
""hello"",""there""

or this one:

foo,bar
'"hello"','"there"'

I believe this is due to using JSON.stringify to encode fields for output, which encloses each field in double-quotes and escapes double-quotes in the data itself with a backslash (which I don't think is correct according to RFC-4180).

Reading undefined "reduced"

`<q-btn
outline
class="q-ma-sm"
color="primary"
label="Export to CSV"
@click="csvDownload(usersPermissionsFlat)"
:data="result.data"
filename="users.csv"
/>

import csvDownload from 'json-to-csv-export'

return {
csvDownload
}`

Error comes up saying reading undefined "reduce" at Proxy.csvDownload2 (index.js:14:41)

not sure how to solve the issue.

Declare headers and data together

Hello, I just wanted to share my way to declare headers and data which I believe is easier in most cases, especially when there is a lot of columns. Just in case it helps anyone or you are open to add something similar baked in the lib.

Basically, I declare my data like this:

const columns: CsvColumn<Person>[] = [
    {
      title: 'First Name',
      getContent: (p) => p.firstName,
    },
    {
      title: 'Last Name'
      getContent: (p) => p.lastName,
    }
  ]

This is possible thanks to this small helper:

import type csvDownload from 'json-to-csv-export'

type CsvDownloadProps = Parameters<typeof csvDownload>[0]

export type CsvColumn<T> = {
  title: string
  getContent: (value: T) => string | null | number | undefined
}

export const getCsvDownloadProps = <T>({
  columns,
  data,
  ...props
}: Omit<CsvDownloadProps, 'data' | 'headers'> & {
  columns: CsvColumn<T>[]
  data: T[]
}): CsvDownloadProps => {
  return {
    ...props,
    headers: columns.map((c) => c.title),
    data: data.map((d) => columns.map((c) => c.getContent(d) ?? '')),
  }
}

Hiding first CSV file row

Screen Shot 2022-09-13 at 9 12 53

When exporting to CSV it generates first row with columns indexes.
Please add the ability to hide it.
Thanks

This is the PR with suggested change.
#36

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

rewrite code in TS

Hey! How about Idea to rewrite code in TS? I can do it (already done actually)

`headers` order isn't respected when `data` is an array of objects

In the following case:

csvDownload({
  headers: ["first_column", "second_column"],
  data: [{ second_column: 2, first_column: 1 }],
  delimiter: ",",
});

...the output will actually be this, which is incorrect:

first_column,second_column
2,1

I haven't looked at the source code, but I imagine what's happening is that if data is an object, the library just serializes the object without regard for headers. But ideally it should read properties from each row object in the order of headers.

It's easy enough to fix in my own code, like this:

const headers = ["first_column", "second_column"]
const data = [{ second_column: 2, first_column: 1 }]
csvDownload({
  headers,
  data: data.map(row => headers.map(columnId => row[columnId])),
  delimiter: ",",
});

But ideally your library could do that so we don't have to :)

Issue in export Hebrew text - add UTF-8 BOM to CSV export

Thanks for the great tool!
I found an issue - The CSV file should be saved as UTF-8 otherwise Excel and other encoding-sensitive applications may show gibberish instead of Hebrew characters.

You can see the Title column:
utf-8 export issue

If I open the file with Notepad or import it to excel using Excel Data tools - all good.
I think the solution is to add UTF-8 BOM to CSV export, maybe this could help:
https://stackoverflow.com/questions/17879198/adding-utf-8-bom-to-string-blob/27975629#27975629

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

File not showing zeros

Hi ;]
When i download a json with some zeros in it is seems as blank in the csv file.

example data:

[
    [
        "DATE",
        "UNITֹ SEEN",
        "ENGAGEMENT",
        "CONVERSION",
        "SUBSCRIBERS",
        "UNIT START",
        "EFFECTIVE CTR",
        "COMPLETION RATE",
        "ADDED TIME(min)"
    ],
    [
        "Jul 28, 2022",
        4762501,
        453675,
        0,
        3,
        362542,
        "7.61%",
        "6.85%",
        "0:0m"
    ],
]

I can make a pr for that

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.