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

ChoETL.json converting JSON with string arrays to CSV files then cannot be restored to the original JSON #263

Open
Ethan-oss-dot opened this issue Jan 11, 2023 · 5 comments

Comments

@Ethan-oss-dot
Copy link

If I have a json string like this:
{ "BATCH_CODE": ["1", "2"] "WIP_CODE":[] }
When I use code
using (var r = new ChoJSONReader(str)) { using (var w = new ChoCSVWriter(path).Configure(c => c.NestedColumnSeparator = '/').WithFirstLineHeader()) { w.Write(r); } }
In CSV file column it will be
image
Then I want to convert the csv file back to the original json and find that it cannot be restored,but it failed
using (var w = new ChoJSONWriter(json) .Configure(c => c.DefaultArrayHandling = false) ) { using (var r = new ChoCSVReader(str).WithFirstLineHeader() .Configure(c => c.ArrayIndexSeparator = '/') ) w.Write(r); }
it will be
{ "BATCH_CODE": { "0": "1", "1": "2" } }
Can you help me?

@Cinchoo
Copy link
Owner

Cinchoo commented Jan 13, 2023

put together sample fiddle, take a look at it. Let me know.

https://dotnetfiddle.net/Yk2pvT

FYI, pls take the latest version.

@Ethan-oss-dot
Copy link
Author

Thanks for the answer, this is useful, but it's not a generic method, it requires me to have to know the field names of the array.

@Cinchoo
Copy link
Owner

Cinchoo commented Jan 18, 2023

Well, as the csv can't capture the state of the empty (WIP_CODE) array. no way for the json parser reconstruct it back to empty array. Hence you need to explicitly tell it to create one as empty.

@zhengtg
Copy link

zhengtg commented Apr 17, 2023

Well, as the csv can't capture the state of the empty (WIP_CODE) array. no way for the json parser reconstruct it back to empty array. Hence you need to explicitly tell it to create one as empty.

@Cinchoo
has any way parse csv back to json in defferent size of array?
this is the sample code. i want to remove the empty object (all field of object is null or default value) in list.
https://dotnetfiddle.net/9E3rH0

@Cinchoo
Copy link
Owner

Cinchoo commented Aug 8, 2023

Here is how you can convert csv back to expected json.

https://dotnetfiddle.net/kEyFwo

PS: this feature (nullvaluehandling) will be added to framework in future.

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