Skip to content

Force conversion of all fields to strings #149

@lejacobroy

Description

@lejacobroy

Background Information

  • Module Version: 3.7.0
  • Node/Browser Version: 13.13.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 have a csv with some rows that contains the string "39e1804". I want it to be a string when converted to json.

Actual Behavior

The csv string "39e1804" gets read as a number in scientific representation, and converted to the number "Infinity". Even if I use toString(), it reports the string "Infinity", since that's the number converted to string.

Data Sample

My csv gets read as a buffer, converted to string and then sent to csv2json.
CSV:

"code1,code2
test,39e1804"

(or)

JSON:

Code Example

// Please include a simple example to replicate the issue
let converter = require('json-2-csv');

const options = {
                delimiter: {
                  eol: '\r\n'
                },
                excelBOM: true,
                excelStrings: true
              };
let final_json = await converter.csv2jsonAsync(file.data.toString(), options)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions