This question has been asked many times, but I could not find an answer that fixes my problem.
I am trying to convert a nested JSON format to CSV format as follows:
The JSON structure is arbitrary and can be anything , nested or not.
I should not know this, this is a response to the database, and I need to export this JSON response to a CSV file.
Here is an example
Input:
{ "_id": 1, "name": "Aurelia Menendez", "scores": [ { "type": "exam", "score": 60.06045071030959 }, { "type": "quiz", "score": 52.79790691903873 }, { "type": "homework", "score": 71.76133439165544 } ] }
The result I'm looking for:
_id,name,scores.type,scores.score,scores.type,scores.score,scores.type,scores.score 1,Aurelia Menendez,exam,60.06...,quiz,52.79...,homework,71.76..
This is an example, it can be any other JSON document.
The idea here is to use dot notation in the CSV column name.
I already used CDL, but the result is not the one I want:
_id scores name 1 "[{score:60.06045071030959,type:exam},{score:52.79790691903873,type:quiz},{score:71.76133439165544,type:homework}]" Aurelia Menendez
So, how can I convert nested JSON to CSV with dotted notation and a common way?
edits
Deserialization JSON with Jackson :
ObjectMapper mapper=new ObjectMapper(); JsonNode jsonNode=mapper.readValue(new File("C:\\...\\...\...\\test.json"), JsonNode.class);
Ismail