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

Added an option to only select required fields #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

varnitsingh
Copy link

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
Copy link
Author

resolves #35

@vinay20045
Copy link
Owner

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.

if len(sys.argv) > 4:
for i in range(4,len(sys.argv)):
acceptable_keys.append(sys.argv[i])
print('Only copying from: ',end='')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is throwing syntax error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try removing end=''. See if that works. There is a issue sometimes with the python linter.

@varnitsingh
Copy link
Author

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.

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

Successfully merging this pull request may close these issues.

None yet

2 participants