I am working on a script to read JSON from a file and then to extract a certain content to a different table. I am able to read from the file and parse the list of books out(in the example). The issue is since I am writing to a table, not every list has the same fields. I want to send default values in the JSON.So this is the JSON I have. I want to end up writing the JSON
{
"books": [
{
"field1": "value",
"field2": "value",
"field3": "value"
},
{
"field1": "value",
"field2": [
"value"
],
"field3": "value",
"field4": "value"
},
{
"field1": "value",
"field2": "value",
"field3": "value",
"field4": "value",
"field5": "value"
}
]
}
I am trying to write these values to a csv. I thought the next intermediate step might be to have a flattened structure like the following. So basically empty strings and then I could write this to an CSV. I am not clear how to do this if anyone has suggestions. Thanks!
[
{
"field1": "value",
"field2": "value",
"field3": "value",
"field4": "",
"field5": ""
},
{
"field1": "value",
"field2": [
"value"
],
"field3": "value",
"field4": "value",
"field5": ""
},
{
"field1": "value",
"field2": "value",
"field3": "value",
"field4": "value",
"field5": "value"
}
]