Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Json Complex Object outputting all keys as headers #91

Open
ChazUK opened this issue Feb 4, 2021 · 11 comments
Open

CLI: Json Complex Object outputting all keys as headers #91

ChazUK opened this issue Feb 4, 2021 · 11 comments

Comments

@ChazUK
Copy link

ChazUK commented Feb 4, 2021

I have a complex JSON object in a file that when running via the CLI outputs the keys as headers

jsonexport complex.json output.csv

complex.json

{
  "complex": {
    "object": 1,
    "that": 2
  },
  "has": 3,
  "nested": {
    "keys": true
  }
}

output.csv

complex.object,complex.that,has,nested.keys
1,2,3,true

but running it via the online demo page https://kaue.github.io/jsonexport/demo/?json={%22complex%22:{%22object%22:1,%22that%22:2},%22has%22:3,%22nested%22:{%22keys%22:true}}&options={}

it comes out as expected

complex.object,1
complex.that,2
has,3
nested.keys,true
@AckerApple
Copy link
Collaborator

AckerApple commented Feb 4, 2021

Acknowledged but not expecting immediate reaction without tighter connection to what is the cause.

I have an educated guess: The options in the demo, even when blank/default I believe, are still sending those blank/default values which perhaps are being seeing as altering arguments...

If you catch my drift above, our goal would be to console log the options in the demo and then exactly send those options in your NodeJs usage.

Based on your skill level, if you cloned our gh-pages branch and console logged the options at runtime you could get our answer. The file to edit would be gh-pages/demo/src/index.js@update:45

Good luck and may Feb 4th be with you

@ChazUK
Copy link
Author

ChazUK commented Feb 4, 2021

Console logged options var from the gh-pages branch and it's an empty object. verticalOutput: true is still set as the default.

@ChazUK
Copy link
Author

ChazUK commented Feb 4, 2021

edited the code and ran ./node_modules/jsonexport/bin/jsonexport.js a.json b.csv to output the CLI options

{
  headers: [],
  rename: [],
  headerPathString: '.',
  rowDelimiter: ',',
  textDelimiter: '"',
  arrayPathString: ';',
  undefinedString: '',
  endOfLine: '\n',
  mainPathItem: null,
  booleanTrueString: null,
  booleanFalseString: null,
  includeHeaders: true,
  fillGaps: false,
  verticalOutput: true,
  forceTextDelimiter: false }

which matches the default options of

{
	"headers": [],
	"rename": [],
	"headerPathString": ".",
	"rowDelimiter": ",",
	"textDelimiter": "\"",
	"arrayPathString": ";",
	"undefinedString": "",
	"endOfLine": "\n",
	"mainPathItem": null,
	"booleanTrueString": null,
	"booleanFalseString": null,
	"includeHeaders": true,
	"fillGaps": false,
	"verticalOutput": true,
	"forceTextDelimiter": false
}

Not sure if this matters but your bin/jsonexport.js which I'm guessing is what the command line uses is referring to lib/index.js rather than dist/index.js

@AckerApple
Copy link
Collaborator

Hmmmmmm, nothing definitive coming from that... It was an educated guess at best but if no answers coming from that than we need more research and debugging

@ChazUK
Copy link
Author

ChazUK commented Feb 4, 2021

The loaded file is being consumed as

[ { complex: { object: 1, that: 2 },
    has: 3,
    nested: { keys: true } } ]

looking into why, are you happy for me to create a PR once I find a fix?

@ChazUK
Copy link
Author

ChazUK commented Feb 4, 2021

Looks like this is the culprit, https://github.com/kaue/jsonexport/blob/master/lib/core/stream.js#L45

I think

let data = self._wrapArray(parts.join("}"));
json = JSON.parse(data);

can just be

json = JSON.parse(chunk);

@AckerApple
Copy link
Collaborator

By all means. Create the PR please and thank you. It may sit for a little due to schedules and such. I am just acting as front line communications, for this issue, so do not gain expectation of fast action.

@ChazUK
Copy link
Author

ChazUK commented Sep 29, 2021

@AckerApple I have had a PR open for a few months now, has this been looked at or put into any kind of roadmap?

@AckerApple
Copy link
Collaborator

This was news to me, as of just now. I will attempt to review soon.

@AckerApple
Copy link
Collaborator

Oh hey I recall that now. I see you are getting help. I just contribute where I can here and there

@kaue
Copy link
Owner

kaue commented Sep 29, 2021

Yeah, we should be good here @AckerApple :) forgot to check the issues, still have a lot to catch up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants