Comments (12)
Thanks for posting this, Herve. I agree that the ordering of the document keys should not cause the schema error that you are receiving. I'm working on fixing this and should have it fixed in the near future (hopefully tomorrow or Friday). Sorry for the inconvenience this may have caused.
from json-2-csv.
Thanks again for reporting this. It should be fixed in NPM version 1.1.0 which I just published. If you experience any other problems with the module, please let me know.
from json-2-csv.
Thanks for your fix. All is good and my tests are ok :-)
2015-04-10 14:38 GMT+02:00 Mike Rodrigues [email protected]:
Thanks again for reporting this. It should be fixed in NPM version 1.1.0
which I just published. If you experience any other problems with the
module, please let me know.—
Reply to this email directly or view it on GitHub
#12 (comment).
from json-2-csv.
Hi,
I reproduce this problem :-(
[ '"_id";"address";"name";"Tag"',
'"_id";"name";"address";"Tag"' ]
I can give you a db if you want.
Thanks for your help
Herve
from json-2-csv.
Hi Herve,
Thanks for letting me know. Which version are you using? Could you send me the version number from node_modules/json-2-csv/package.json? I just tried out a simple example using version 1.3.0 and it appears to be working as expected. Here's my test example for reference:
var json2csv = require('json-2-csv');
var docs = [
{
'_id': '235235626324342',
'name': 'Mike',
'address': 'Test1123',
'Tag': 'mytag'
},
{
'_id': '456365834905679',
'address': 'Var123',
'name': 'Joe Shmoe',
'Tag': 'notag'
}
];
json2csv.json2csv(docs, function (err, csv) {
if (err) { return console.log(err); }
console.log('success', csv);
});
Thanks,
Mike
from json-2-csv.
Hi Mike,
I'm in 1.3.0 version
With your example it's ok.
I've joined my extract and the error at the last line. cf output.log
Thanks
Herve
2015-06-08 16:50 GMT+02:00 Mike [email protected]:
Hi Herve,
Thanks for letting me know. Which version are you using? Could you send me
the version number from node_modules/json-2-csv/package.json? I just tried
out a simple example using version 1.3.0 and it appears to be working as
expected. Here's my test example for reference:var json2csv = require('json-2-csv');
var docs = [
{
'_id': '235235626324342',
'name': 'Mike',
'address': 'Test1123',
'Tag': 'mytag'
},
{
'_id': '456365834905679',
'address': 'Var123',
'name': 'Joe Shmoe',
'Tag': 'notag'
}
];json2csv.json2csv(docs, function (err, csv) {
if (err) { return console.log(err); }
console.log('success', csv);
});Thanks,
Mike—
Reply to this email directly or view it on GitHub
#12 (comment).
from json-2-csv.
Hmm. Is there any way that you could provide an example so I can take a look? Seems like it would be an issue with lines 37-40 of json-2-csv.js:
var diff = _.difference(firstDocSchema, _.flatten(keyList));
if (!_.isEqual(diff, [])) {
schemaDifferences++;
}
from json-2-csv.
Sorry this is the link to download an example included in this file :
<removed by @mrodrig>
Thanks
Herve
2015-06-09 1:10 GMT+02:00 Mike [email protected]:
Hmm. Is there any way that you could provide an example so I can take a
look? Seems like it would be an issue with lines 37-40 of json-2-csv.js:var diff = _.difference(firstDocSchema, .flatten(keyList));
if (!.isEqual(diff, [])) {
schemaDifferences++;
}—
Reply to this email directly or view it on GitHub
#12 (comment).
from json-2-csv.
Hi Herve,
Thanks for the log file. It looks like the reason why it's throwing the 'Schema not the same' error is because a few of the documents towards the top have a 'name' attribute, and others do not. One option to fix this would be to run a loop like this over the data before calling json2csv:
(example using underscore)
// Fetch documents from the database
var documents = ... ;
// Loop over the documents to ensure the schemas are the same
documents = _.map(documents, function (document) {
// Set the document's name attribute to an empty string if it does not exist
document.name = document.name ? document.name : '';
return document;
});
In the future I might look into removing that error and just having the module use null
or ''
as a default value if the key doesn't exist.
Hope this helps!
Thanks,
Mike
from json-2-csv.
Hi Mike,
thank you for this help.
I'll implement it.
Thanks :-)
Herve
2015-06-09 14:34 GMT+02:00 Mike [email protected]:
Hi Herve,
Thanks for the log file. It looks like the reason why it's throwing the
'Schema not the same' error is because a few of the documents towards the
top have a 'name' attribute, and others do not. One option to fix this
would be to run a loop like this over the data before calling json2csv:
(example using underscore)// Fetch documents from the database
var documents = ... ;// Loop over the documents to ensure the schemas are the same
documents = _.map(documents, function (document) {
// Set the document's name attribute to an empty string if it does not exist
document.name = document.name ? document.name : '';
return document;
});In the future I might look into removing that error and just having the
module use null or '' as a default value if the key doesn't exist.Hope this helps!
Thanks,
Mike—
Reply to this email directly or view it on GitHub
#12 (comment).
from json-2-csv.
This is my fix in my code :
var result = docs.map(function (doc) {
for (var i = 0, len = fields.length; i < len; i++) {
if (typeof newdoc[fields[i]] == 'undefined') {
newdoc[fields[i]] = "";
}
}
return newdoc;
});
It works fine :-)
Thanks
Herve
2015-06-09 14:34 GMT+02:00 Mike [email protected]:
Hi Herve,
Thanks for the log file. It looks like the reason why it's throwing the
'Schema not the same' error is because a few of the documents towards the
top have a 'name' attribute, and others do not. One option to fix this
would be to run a loop like this over the data before calling json2csv:
(example using underscore)// Fetch documents from the database
var documents = ... ;// Loop over the documents to ensure the schemas are the same
documents = _.map(documents, function (document) {
// Set the document's name attribute to an empty string if it does not exist
document.name = document.name ? document.name : '';
return document;
});In the future I might look into removing that error and just having the
module use null or '' as a default value if the key doesn't exist.Hope this helps!
Thanks,
Mike—
Reply to this email directly or view it on GitHub
#12 (comment).
from json-2-csv.
Great - Glad we were able to solve it!
Thanks,
Mike
from json-2-csv.
Related Issues (20)
- Headerless CSV HOT 3
- Incorrect parsing of wrapped values HOT 5
- Custom sorting of headers HOT 2
- How to properly change mongoDB timestamp to proper date? HOT 1
- TypeError: Cannot convert undefined or null to object HOT 1
- Private Vulnerability Disclosure HOT 1
- csv2json Allow CSV Files Without Headers HOT 3
- NestedDotKeys with false and 0 are returned as undefined HOT 4
- prependHeader: false, is not working HOT 2
- Paginated conversion ? HOT 1
- "expandArrayObjects" option not behaving as expected HOT 3
- sync version HOT 2
- Incorrect parsing of wrapped values when the new line is right after the starting quote HOT 1
- Ignoring an entire array with `excludeKeys` and `expandArrayObjects` HOT 2
- No possibility to use unescaped dots in headers HOT 11
- Feature Request: expandNestedObjects functionality with keys HOT 10
- Providing option.keys[] field with RegExp throws kp.slice() is not a function HOT 2
- Add support for RegExps in excludeKeys
- Field in CSV it turned into an object unexpectedly. HOT 2
- why json to csv adds `\` before `.` in headers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-2-csv.