if fileExtension not in file_types:
    parser.error("%s has an invalid file type.\nPlease use one of the following\
%s." % (arg, file_types))
  if not os.path.isfile(doc_path + arg):
    parser.error("%s does not exist." % arg)
  return arg

parser = argparse.ArgumentParser(description='Transform document into JSON.')
parser.add_argument('-t', action='store_true', help='Use schema template for transform')
parser.add_argument('mode', type=str, help='Mode for transformation', choices=['program','pubs','software'])
parser.add_argument('file_name', type=lambda x: is_valid_file(parser, x), help='List of files to be transformed, need at least 1', nargs='+')

args = vars(parser.parse_args())
mode = args['mode']
template = args['t']
schemas = gs.get_schemas()

# Matches the schema with the appropriate type after
# being 
for i in range(len(schemas)):
  if i % 2 == 0:
    if schemas[i] == "Publication":
      pub_schema = schemas[i+1]
    elif schemas[i] == "Software":
      software_schema = schemas[i+1]
    else:
      program_schema = schemas[i+1]

# Represents the schema that will be used in parsing
schema = 0
                json.dump(json_data,
                          output,
                          sort_keys=False,
                          indent=4,
                          ensure_ascii=False)
        except Exception, e:
            print "\nFAILED! Could not update %s json file for %s" % (
                file_name, program_name)
            print " Details: %s" % str(e)

        print "Changed %i entries in %s" % (changes, file_name)

    return changes


schemas = gs.get_schemas()  # List of schemas from template file

# Determines the type of schemas given from the template file
for i in range(len(schemas)):
    if i % 2 == 0:
        if schemas[i] == "Publication":
            pub_schema = schemas[i + 1]
        elif schemas[i] == "Software":
            software_schema = schemas[i + 1]
        else:
            program_schema = schemas[i + 1]

found_key = False  # Boolean which determines if the user's key was
# found in any of the JSON schemas

# Paths of all JSON file types in the open catalog
              changes += 1
  
  # Only writes updated JSON file if something changed
  if changes > 0:
    try:
      with open(json_file, 'w') as output:
        json.dump(json_data, output, sort_keys = False, indent = 4, ensure_ascii=False)
    except Exception, e:
      print "\nFAILED! Could not update %s json file for %s" % (file_name, program_name)
      print " Details: %s" % str(e)
    
    print "Changed %i entries in %s" % (changes, file_name)

  return changes

schemas = gs.get_schemas() # List of schemas from template file

# Determines the type of schemas given from the template file
for i in range(len(schemas)):
  if i % 2 == 0:
    if schemas[i] == "Publication":
      pub_schema = schemas[i+1]
    elif schemas[i] == "Software":
      software_schema = schemas[i+1]
    else:
      program_schema = schemas[i+1]

found_key = False # Boolean which determines if the user's key was
                  # found in any of the JSON schemas

# Paths of all JSON file types in the open catalog