Skip to content

Instantly share code, notes, and snippets.

@userow
Created October 2, 2016 14:09
Show Gist options
  • Save userow/8491e176514c8e685febee6cd38360e2 to your computer and use it in GitHub Desktop.
Save userow/8491e176514c8e685febee6cd38360e2 to your computer and use it in GitHub Desktop.
Filters out only one appID from parse exported json
#!/usr/bin/python
#usage:
# python filter_app_id.py source.json destination.json com.application.identifier
import sys, json
inputfile = sys.argv[1]
outputfile = sys.argv[2]
appID = sys.argv[3]
input_json = open(inputfile, "r").read()
# Transform json input to python objects
in_results = json.loads(input_json)
input_dict = in_results["results"]
# Filter python objects with list comprehensions
output_dict = [x for x in input_dict if (x["deviceType"] == "ios") and (x["appIdentifier"] == appID)]
output_results = { "results" : output_dict }
# Transform python object back into json
output_json = json.dumps(output_results)
# Show json
#print output_json
text_file = open(outputfile, "w")
text_file.write(output_json)
text_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment