Comments (12)
Build an example of your issue here and then paste us the link:
https://kaue.github.io/jsonexport/demo/
Then include annotated screen capture highlighting issue on that page.
We need better examples and illustrations from you please and thank you
from jsonexport.
Sure - not a problem. If we can contribute then I will have a go if I can find some time! Same for all of us :-)
from jsonexport.
I think that the issue happens when you get child objects that may not have the same fields for each record. I have updated the demo JSON with an "interests" object.
I looked at the header and then made sure that someone with a nickname had the Interests object.
As a result, Bob and James are not correct because they are missing trailing commas to complete the line.
Only David has the correct number of commas (and this is because he has a nick name and this is the last header entry).
I think that there should be the same number of comma delimiters per row as there are header entries?
Here is the JSON for the demo:
[
{
"name":"Bob",
"lastname":"Smith",
"family":{
"name":"Peter",
"type":"Father"
},
"interests":{
"music":"jazz"
}
},
{
"name":"James",
"lastname":"David",
"family":{
"name":"Julie",
"type":"Mother"
},
"interests":{
"books":"pulp fiction"
}
},
{
"name":"Robert",
"lastname":"Miller",
"family":null,
"location":[
1231,
3214,
4214
]
},
{
"name":"David",
"lastname":"Martin",
"nickname":"dmartin",
"interests":{
"books":"pulp fiction"
}
}
]
and this is the CSV you get
name,lastname,family.name,family.type,interests.music,interests.books,family,location,nickname
Bob,Smith,Peter,Father,jazz -MISSING TRAILING COMMAS
James,David,Julie,Mother,,pulp fiction - MISSING TRAILING COMMAS
Robert,Miller,,,,,,1231;3214;4214 -MISSING TRAILING COMMAS
David,Martin,,,,pulp fiction,,,dmartin - OK
from jsonexport.
Simplified direct link to reproduce issue here
Ok, I can see what you are calling out in that we need extra commas at the end.
Not sure who will get to this and we invite you to try and make a PR for it as well. I do not have time currently to address in any immediate fashion.
from jsonexport.
@MelissaSnell I just noticed pull request #81 might just be your fix. It has conflicts right now but if worked out I believe it aims to address your issue
from jsonexport.
Great! I will take a look. Thank you.
from jsonexport.
Any hope of that feature in #81 being merged? The need to deal with sparse objects is very real.
from jsonexport.
@bestekov have you checked out and tried #81? I tried briefly reviewing and I'm too out of context with what's going on to verify. It may help to have you provide insight here and any supporting evidence of it being a needed solution.
I read through past comments and saw we were going to work towards confirmations ourselves but life.
from jsonexport.
Will see if I can get some time to try to run tests. But the basic gist is there should be a unit test of an object like:
[
{ foo: 'a1', bar: 'b1' },
{ foo: 'a2', bar: 'b2', qux: 'd2' },
{ foo: 'a3', bar: 'b3', baz: 'c3' }
]
And that should result in:
foo,bar,qux,baz
a1,b1,,
a2,b2,d2,
a3,b3,,c3
Where today without a fix you instead get:
foo, bar, qux, baz
a1,b1 // the lack of trailing commas breaks things
a2,b2,d2
a3,b3,,c3
from jsonexport.
@AckerApple , I tried #81 , but it did not appear to fix this issue. Any hope of a fix to trailing commas?
Or, alternatively, is there any way to specify that it should output columns in a particular order? Then maybe I could put a column I know will always have a value at the end of the header list to ensure that extra commas are inserted internally to the row (since that appears to work okay).
from jsonexport.
@bestekov try using the headers
option.
headers - Array Used to set a custom header order, defaults to [] example ['lastname', 'name']
from jsonexport.
I will try catching up with this issue and with PR reviews when i get some free time.
from jsonexport.
Related Issues (20)
- Stream does not support typeHandlers option HOT 3
- How to remove the title option from inside xls file
- Nested JSONObject not correctly mapping to csv
- Update v2.5.2 to v2.5.3 with Bug Fixes for package.json stuck on v2
- verticalOutput with Arrays HOT 1
- No option to ignore fields / limit fields to export ? HOT 2
- large files not converting HOT 10
- (I think I) found a bug HOT 6
- typeHandlers tests & more samples
- speed question/issue HOT 4
- Column values with zero (0) are being replaced with "" HOT 3
- Complex JSON array - unexpected behavior HOT 1
- Need Help : Complex Json Array to CSV HOT 2
- Json Complex Example HOT 2
- JSON Array not converting to CSV HOT 1
- TypeError: this._options.handleDate is not a function HOT 5
- typeHandlers is not part of UserOptions HOT 2
- CLI: Json Complex Object outputting all keys as headers HOT 11
- Exporting a dataset with a hashtag (#) in a string breaks CSV HOT 1
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 jsonexport.