Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Object key order matters when exporting to CSV - ideally shouldn't be? #2718

Closed
1 task
nktnet1 opened this issue Oct 18, 2024 · 0 comments · Fixed by #2734
Closed
1 task

[Bug] Object key order matters when exporting to CSV - ideally shouldn't be? #2718

nktnet1 opened this issue Oct 18, 2024 · 0 comments · Fixed by #2734
Assignees
Labels
bug Something isn't working. t-tooling Issues with this label are in the ownership of the tooling team.

Comments

@nktnet1
Copy link

nktnet1 commented Oct 18, 2024

Which package is this bug report for? If unsure which one to select, leave blank

@crawlee/core

Issue description

  1. Create a dataset
  2. Push an object, e.g.
    { name: 'John', age: 30 }
  3. Push another object with the same keys, but different order, e.g.
    { age: 42, name: 'Adam' }
  4. Export the dataset to a CSV file
  5. Observe that the output is
    name,age
    John,30
    42,Adam
    

I would've expected the order of keys->columns to be determined by the first object in the dataset, e.g.

name,age
John,30
Adam,42

Or otherwise, the importance of key order should be noted somewhere in the docs.

Code sample

import { Dataset } from 'crawlee';

const main = async () => {
  const datasetName = 'example-dataset';

  let dataset = await Dataset.open(datasetName);
  await dataset.drop();

  dataset = await Dataset.open(datasetName);

  await dataset.pushData({ name: 'John', age: 30 });
  await dataset.pushData({ age: 42, name: 'Adam' });

  await dataset.exportToCSV(`${datasetName}.csv`);
  console.log((await dataset.getData()).items);
};

void main();

Package version

3.11.5

Node.js version

v20.17.0

Operating system

MacOS, Linux (Arch)

Apify platform

  • Tick me if you encountered this issue on the Apify platform

I have tested this on the next release

No response

Other context

image
@nktnet1 nktnet1 added the bug Something isn't working. label Oct 18, 2024
@github-actions github-actions bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Oct 18, 2024
@B4nan B4nan self-assigned this Oct 21, 2024
B4nan added a commit that referenced this issue Nov 1, 2024
@B4nan B4nan closed this as completed in b66784f Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. t-tooling Issues with this label are in the ownership of the tooling team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants