Code Monkey home page Code Monkey logo

Comments (12)

AckerApple avatar AckerApple commented on June 16, 2024 1

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.

MelissaSnell avatar MelissaSnell commented on June 16, 2024 1

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.

MelissaSnell avatar MelissaSnell commented on June 16, 2024

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.

AckerApple avatar AckerApple commented on June 16, 2024

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.

AckerApple avatar AckerApple commented on June 16, 2024

@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.

MelissaSnell avatar MelissaSnell commented on June 16, 2024

Great! I will take a look. Thank you.

from jsonexport.

bestekov avatar bestekov commented on June 16, 2024

Any hope of that feature in #81 being merged? The need to deal with sparse objects is very real.

from jsonexport.

AckerApple avatar AckerApple commented on June 16, 2024

@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.

bestekov avatar bestekov commented on June 16, 2024

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.

bestekov avatar bestekov commented on June 16, 2024

@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.

kaue avatar kaue commented on June 16, 2024

@bestekov try using the headers option.

headers - Array Used to set a custom header order, defaults to [] example ['lastname', 'name']

from jsonexport.

kaue avatar kaue commented on June 16, 2024

I will try catching up with this issue and with PR reviews when i get some free time.

from jsonexport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.