json-to-csv icon indicating copy to clipboard operation
json-to-csv copied to clipboard

Added an option to only select required fields

Open varnitsingh opened this issue 4 years ago • 3 comments

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>

varnitsingh avatar Oct 02 '20 11:10 varnitsingh

resolves #35

varnitsingh avatar Oct 02 '20 12:10 varnitsingh

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...

  1. 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?
  2. Should the fields be excluded from the output csv or input json?
  3. What happens to complex relationships? As in, if let's say parent2 is being requested in a case like parent1.parent2.parent3.child1 = value by the user then how to handle?
  4. What happens to dictionary inside list?
  5. The script in it's current from can handle non-homogeneous objects. Will implementation vary for these?

Let me know what you think.

vinay20045 avatar Oct 02 '20 17:10 vinay20045

Answering your questions

  1. The acceptable fields are only at level one. The arguments specify which fields to keep in the final output csv file.
  2. Fields not mentioned in the arguments are excluded from the final output csv file.
  3. Right now only level one fields are being worked upon, I can write something to handle complex relationships. For parent2 argument could be parent1.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.

varnitsingh avatar Oct 03 '20 08:10 varnitsingh