@@ -0,0 +1,1612 @@
+# Quick tool to merge two JSON files together%0A# Used in MuteTab to get Manifest file how I want it with OpenForge.%0A#%0A# Usage: mergejson file1 file2 outfile%0A#%0A# Order matters (i.e. if same field is in both, then the contents of file2 will overwrite the contents of file1).%0A#%0A# Written by Jared Sohn 9/15/13%0A#%0A# TODO: At the moment this unfortunately does not merge arrays but instead replaces one instance with the other.%0A%0Aimport simplejson%0Aimport sys%0Aimport copy%0A%0A# from http://blog.impressiver.com/post/31434674390/deep-merge-multiple-python-dicts%0Adef dict_merge(target, *args):%0A  # Merge multiple dicts%0A  if len(args) %3E 1:%0A    for obj in args:%0A      dict_merge(target, obj)%0A    return target%0A %0A  # Recursively merge dicts and set non-dict values%0A  obj = args%5B0%5D%0A  if not isinstance(obj, dict):%0A    return obj%0A  for k, v in obj.iteritems():%0A    if k in target and isinstance(target%5Bk%5D, dict):%0A      dict_merge(target%5Bk%5D, v)%0A    else:%0A      target%5Bk%5D = copy.deepcopy(v)%0A  return target%0A%0A%0A%0A# get args (filenames)%0Aif len(sys.argv) == 4:%0A%09input1_filename = sys.argv%5B1%5D%0A%09input2_filename = sys.argv%5B2%5D%0A%09output_filename = sys.argv%5B3%5D%0Aelse:%0A%09print 'Usage: mergejson inputfile1 inputfile2 outputfile'%0A%09sys.exit(0)%0A%0A# read files%0Af = open(input1_filename, 'r')%0Afile1_contents = f.read()%0Af.close()%0Af = open(input2_filename, 'r')%0Afile2_contents = f.read()%0Af.close()%0A%0A# combine files%0Ajson1 = simplejson.loads(file1_contents)%0Ajson2 = simplejson.loads(file2_contents)%0Amerged = dict_merge(json1, json2)%0Aoutputjson = simplejson.dumps(merged, indent=2)%0A%0A# write output%0Af = open(output_filename, 'w')%0Af.write(outputjson)%0Af.close()%0A

Create mergejson.py