types
shaylang opened this issue · comments
hi Keyang,
Is there a way to tell the parser how to convert a column type?
for example, i have this csv data:
name, timestamp, value
a.b.c.d.e.f, 1397434200, 1.82
yield this json:
[ { name: 'a.b.c.d.e.f', timestamp: '1397434200', value: '1.82' } ]
i would like that timestamp and value will be a number and not a string
thanks in advance,
Shay
currently it is not supported.
But it will be supported.
+1
any idea when this will happen?
+1 :)
+1
+1
change following line in parser_json.js:
pointer[key] = params.item;
TO:
if (isNaN(params.item)) {
//console.log(params.item)
pointer[key]=params.item;
} else {
pointer[key]=parseInt(params.item);
}
👍
@hansdesmedt, your solution works for me. But I need to have boolean type. Maybe we can create a pull-request.
It may be better with this:
try {
pointer[key] = JSON.parse(params.item);
} catch (e) {
pointer[key] = params.item;
}
No permission to create pull-request. Too bad :(
@sk-ericso No permission to create pull-request. Too bad :(
Really? Hows that possible? It is public repo right?
I definitely did not turn the "pull-request" feature off. :D
(well, let me know if I did something wrong with the project)
I am thinking recently adding the type to the header. Someting like date#employee.birthday so the parser could recognise the column as Date type.
Of course, it is still backward compatible with old structure. The type of a column will be optional.
Please let me know how you guys think.
Regards,
Keyang
see the error below:
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --set-upstream origin issue-20:issue-20
Pushing to git@github.com:Keyang/node-csvtojson.git
ERROR: Permission to Keyang/node-csvtojson.git denied to sk-ericso.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Completed with errors, see above
Hi,
I believe you need "fork" the project first and open a pull request through your project page.
See github how to contribute open source project.
https://guides.github.com/activities/contributing-to-open-source/
Hope this helps. :)
Regards,
Keyang
@Keyang the way you proposed to add types (i.e. date#employee.birthday) is absolute OK for me.
Alright. I forked and create a pull-request.
Hi guys,
I have updated the document for field type.
https://github.com/Keyang/node-csvtojson#field-type
Checkout the latest version (0.3.14)
Thanks everyone contributing this.
I will close the ticket.
If you find any bugs, please open a new ticket.
Regards,
Keyang