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

Nested JSONObject not correctly mapping to csv #109

Open
timisenco2015 opened this issue Nov 5, 2022 · 0 comments
Open

Nested JSONObject not correctly mapping to csv #109

timisenco2015 opened this issue Nov 5, 2022 · 0 comments

Comments

@timisenco2015
Copy link

timisenco2015 commented Nov 5, 2022

I am using your package to convert nested JSON objects to CSV but it is not correctly mapping my JSON Object data to CSV.
I have the sample JSON data, the CSV file, and my Node JS code below.
a) CSV file form_buggy_test_submissions.csv
b) JSON data [ { "form": { "confirmationId": "5AB5D586", "formName": "form_buggy_test", "version": 1, "createdAt": "2022-11-04T23:11:37.912Z", "fullName": "Ayobami Idowu", "username": "test", "email": "[email protected]" }, "email": "[email protected]", "submit": true, "oneRowPerLake": [ { "dataGrid": [ { "fishType": "rainbow", "numberKept": 1, "numberCaught": 1 }, { "fishType": "cutthroat", "numberKept": 1, "numberCaught": 1 }, { "fishType": "dollyVardon", "numberKept": 1, "numberCaught": 1 }, { "fishType": "smallmouthBass", "numberKept": 2, "numberCaught": 2 } ], "lakeName": "bron", "closestTown": "brondan", "numberOfDays": 1 }, { "dataGrid": [ { "fishType": "rainbow", "numberKept": 2, "numberCaught": 2 }, { "fishType": "cutthroat", "numberKept": 1, "numberCaught": 1 } ], "lakeName": "dran", "closestTown": "dranard", "numberOfDays": 1 } ], "fishermansName": "Ayobami", "didYouFishAnyBcLakesThisYear": "yes", "forWhichBcLakeRegionAreYouCompletingTheseQuestions": 8 } ]
c) JSON Header
[ 'form.confirmationId', 'form.formName', 'form.version', 'form.createdAt', 'form.fullName', 'form.username', 'form.email', 'fishermansName', 'email', 'forWhichBcLakeRegionAreYouCompletingTheseQuestions', 'didYouFishAnyBcLakesThisYear', 'oneRowPerLake.lakeName', 'oneRowPerLake.closestTown', 'oneRowPerLake.numberOfDays', 'oneRowPerLake.dataGrid.fishType', 'oneRowPerLake.dataGrid.numberCaught', 'oneRowPerLake.dataGrid.numberKept' ]
d) Node JS
`const options = {
fillGaps: false,
fillTopRow: true,
headerPathString:".",
verticalOutput:false,
// Leaving this option here if we need it. This is the original csv setup where the submission just prints out in 1 column as JSON
//definitions to type cast
typeHandlers: {
Object: function (value, name) {
if (value instanceof Object) {
if (name === 'submission') {
// not really sure what the best representation for JSON is inside a csv...
// this will produce a "" string with all the fields and values like ""field"":""value""
return JSON.stringify(value);
}
}
return value;
}
},

    // re-organize our headers to change column ordering or header labels, etc
    headers: await service._buildCsvHeaders(form, data)
  };
  const csv = await jsonexport(data, options);`

# Help Wanted
@andrew @dydx @cburgmer @jclay

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

1 participant