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

Convert Json to CSV issue 2 #325

Open
Karthigeyan14 opened this issue Nov 4, 2024 · 6 comments
Open

Convert Json to CSV issue 2 #325

Karthigeyan14 opened this issue Nov 4, 2024 · 6 comments

Comments

@Karthigeyan14
Copy link

I am facing the 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
Copy link
Author

@Cinchoo #324 Same issue, but I didn't get the solution. Can you suggest a solution to this issue?

@Cinchoo
Copy link
Owner

Cinchoo commented Nov 5, 2024

can't reproduce it. here is working sample

https://dotnetfiddle.net/ipX7aU

Output:

extension_0_Test,extension_0_value_0,extension_0_value_1,extension_0_value_2,extension_1_Test1,extension_1_value,extension_2_Test2,extension_2_value
value,0,1,2,Test,20,Test,35

@Karthigeyan14
Copy link
Author

Karthigeyan14 commented Nov 6, 2024

@Cinchoo I just showed an example; the actual file is different. I tried what you mentioned, but the CSV file output writes all the data in a single line. Since the JSON file contains a lot of data, I need to write each entry separately one by one. I’ve attached the example file. Can you suggest how to fix this?

Sample.json

@Cinchoo
Copy link
Owner

Cinchoo commented Nov 8, 2024

cinchoo etl does the best way possible to convert json to csv. but json is structured file, csv is flat. in order to accomblish the conversion expected way, some custom work is needed.

Based on your input, i've compiled sample fiddle

https://dotnetfiddle.net/zW9iI2

Expected output will be:

testUrl,resourceType,managingtest_test,name_0_lastname,name_0_firstname,name_0_given,gender,birthDate,sata_YearUpdated,url,value_0,value_1,value_2
https://,test,test/1809,,,,male,1925-01-01,2024,www.com,test1,test2,test3
https://,test,test/1809,,,,male,1925-01-01,2024,www.1.com,test20,,
https://,test,test/1809,,,,male,1925-01-01,2024,www.2.com,test30,,
https://,test,test/1809,,,,male,1925-01-01,2024,www.3.com,test40,,
https://,test,test/1810,,,,male,1925-01-01,2024,www.1.com,test20,,
https://,test,test/1810,,,,male,1925-01-01,2024,www.2.com,test30,,
https://,test,test/1810,,,,male,1925-01-01,2024,www.com,test1,test2,test3
https://,test,test/1810,,,,male,1925-01-01,2024,www.3.com,test40,,

Hope this works.

@Karthigeyan14
Copy link
Author

Yes @Cinchoo , it works for the Value field, but in the Name field, it's showing empty. I need all the data from the JSON file to be converted into CSV format.

Cinchoo added a commit that referenced this issue Nov 14, 2024
@Cinchoo
Copy link
Owner

Cinchoo commented Nov 14, 2024

there was issue pulling those data. applied fix, released ChoETL.Core v1.2.1.68

Here is working fiddle

https://dotnetfiddle.net/Q4HZo3

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