Skip to content

Read empty csv entry as nil #51

@folknor

Description

@folknor

Hi

Thanks for the library, I use it extensively and have done for many years now :-D

Would it be possible to get a configure option for how ftcsv should treat empty entries in the parsed CSV when outputting the lua table?

For example, a CSV that looks like this:

"Testing",,"Testing 2"

Ran through this code:

local csvraw = "C1,C2,C3\n\"Testing\",,\"Testing 2\""
local s = require("serpent")
local ftcsv = require("ftcsv")
local luatbl = ftcsv.parse(csvraw, ",", { loadFromString = true, })
print(s.block(luatbl))

Will output this:

{
  {
    C1 = "Testing",
    C2 = "",
    C3 = "Testing 2"
  } --[[table: 0x58e728040940]]
} --[[table: 0x58e728024e40]]

However what I'd like is for C2 to be nil in this case.

Thoughts?

Thanks again!

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