json-to-csv
json-to-csv copied to clipboard
Added an option to only select required fields
added an option to only add selected fields to the csv files by specifying fields after the path arguments
python json_to_csv.py <node> <json_in_file_path> <csv_out_file_path> <field1> <field2>
resolves #35
Hi @varnitsingh,
Thanks for submitting this PR! This not only resolves #35 but is definitely going to be a useful feature. However, I think this needs a bit more discussion around the implementation...
Some initial thoughts/questions I have are...
- The field that is being indicated by the user can be at any level in the json. How to handle this? Does the user get options to remove from everywhere or only at say 1st level?
- Should the fields be excluded from the output csv or input json?
- What happens to complex relationships? As in, if let's say
parent2
is being requested in a case likeparent1.parent2.parent3.child1 = value
by the user then how to handle? - What happens to dictionary inside list?
- The script in it's current from can handle non-homogeneous objects. Will implementation vary for these?
Let me know what you think.
Answering your questions
- The acceptable fields are only at level one. The arguments specify which fields to keep in the final output csv file.
- Fields not mentioned in the arguments are excluded from the final output csv file.
- Right now only level one fields are being worked upon, I can write something to handle complex relationships. For
parent2
argument could beparent1.parent2
4-5. Can you expand on that, I don't know which list or dictionary you are talking about. Also can you give a example of homogeneous object. Also I could also add a delete feature. So with arguments starting with-field1 field2
these fields would be removed from the final output csv file.