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

Issue Converting JSON to CSV File #324

Closed
Karthigeyan14 opened this issue Oct 23, 2024 · 5 comments
Closed

Issue Converting JSON to CSV File #324

Karthigeyan14 opened this issue Oct 23, 2024 · 5 comments

Comments

@Karthigeyan14
Copy link

Actually, I'm facing an issue while converting JSON to a CSV file. I deserialized it with a dynamic object, but the problem is that the headers are generated based on the first set of data. If the next set of data differs from the first, any missing data is not included in the CSV file. Do you have any suggestions...?

@Cinchoo
Copy link
Owner

Cinchoo commented Oct 24, 2024

use WithMaxScanRows on csv writer

            StringBuilder csv = new StringBuilder();
            using (var r = new ChoJSONReader(FileNameSample33JSON)
                .WithJSONPath("$..getUsers[*]", true)
                )
            {
                using (var w = new ChoCSVWriter(csv)
                    .WithFirstLineHeader()
                    .WithMaxScanRows(10)
                    .Configure(c => c.ThrowAndStopOnMissingField = false)
                    )
                    w.Write(r);
            }

@Karthigeyan14
Copy link
Author

Thank you for your response! It's working. 👍

@Karthigeyan14
Copy link
Author

Karthigeyan14 commented Nov 4, 2024

@Cinchoo I have another issue. The field looks like this:

json

"extension": [
{
"Test": "value",
"value": [
"0",
"1",
"2"
]
},
{
"Test1": "Test",
"value": "20"
},
{
"Test2": "Test",
"value": "35"
}
]
The values 20 and 35 are missing because in the first object, the value field is a list, while in the subsequent objects, value is not a list. This inconsistency causes the values to be overlooked.

@Karthigeyan14 Karthigeyan14 reopened this Nov 4, 2024
@Cinchoo Cinchoo closed this as completed Nov 5, 2024
@Cinchoo
Copy link
Owner

Cinchoo commented Nov 5, 2024

duplicate #325

@Karthigeyan14
Copy link
Author

@Cinchoo I have another issue. The field looks like this:

json

"extension": [ { "Test": "value", "value": [ "0", "1", "2" ] }, { "Test1": "Test", "value": "20" }, { "Test2": "Test", "value": "35" } ] The values 20 and 35 are missing because in the first object, the value field is a list, while in the subsequent objects, value is not a list. This inconsistency causes the values to be overlooked.

so how to fix this ..?

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

2 participants