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

[FEATURE]: Add possibility to rename "some" keys when other still will not be filtered out. #269

Open
4 of 5 tasks
Travellerme opened this issue Dec 16, 2024 · 0 comments

Comments

@Travellerme
Copy link

Travellerme commented Dec 16, 2024

Background Information

  • Module Version: json-2-csv
  • Node/Browser Version: 20.11.0

The issue I'm reporting is with:

  • json2csv
  • csv2json

I have...

  • searched to see if an issue has already been reported.
  • verified that my JSON/CSV data is valid (using something like http://jsonlint.com or https://csvlint.io/).
  • tried upgrading to the latest version of json-2-csv (since the issue may already be fixed).

Expected Behavior

I need to rename some fields and leave the auto-detect mechanism in place. It would be nice to add a possibility to rename "some" keys when other still will not be filtered out.
Add a new flag that would include all fields that are not specified in keys option. (for instance includeAutoDetectedKeys)

Actual Behavior

Currently, there is an option to provide a title only for keys that should be in the final csv file. That means I need to specify all fields I want to see and other fields will be skipped.

{
"field": "string", // required
"title": "string", // optional
"wildcardMatch": false, // optional - default: false
}

When specifying keys as an Object, the field property specifies the key path, while title specifies a more human readable field heading.

Data Sample

JSON:
ANY JSON file

Code Example

// Please include a simple example to replicate the issue
let converter = require('json-2-csv');
json2csv(list, {
    escapeHeaderNestedDots: false,
    unwindArrays: false,
    keys: [{
      field: 'data.businessDescription',
      title: 'Business Description'
    }],
    includeAutoDetectedKeys: true,
    emptyFieldValue: '',
    checkSchemaDifferences: false,
    expandNestedObjects: true,
    expandArrayObjects: true
  })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant