Every line of 'how to create json file in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
73 def create_json(path, to_write={}): 74 with open(path, 'w+') as jsonfile: 75 jsonfile.write(json.dumps(to_write, sort_keys=True, indent=4))
25 def python_to_json(python_data): 26 '''Convert python data (tuple, list, dict, etc) into json string''' 27 json_str = json.dumps(python_data, indent=4) 28 return json_str
98 def main(): 99 parts_regex = re.compile(r'tsuru version.*Usage: (.*?)\n+(.*)', re.DOTALL) 100 topic_regex = re.compile(r'tsuru version.*?\n+(.*)\n\n.*?\n\n ', re.DOTALL) 101 102 result = check_output("tsuru | egrep \"^[ ]\" | awk -F ' ' '{print $1}'", shell=True) 103 cmds = result.split('\n') 104 final_result = {} 105 for cmd in cmds: 106 if not cmd: 107 continue 108 result = check_output('tsuru help {}'.format(cmd), shell=True) 109 matchdata = parts_regex.match(result) 110 if matchdata is None: 111 topicdata = topic_regex.match(result) 112 if topicdata is None: 113 print "Ignored command: {}".format(cmd) 114 continue 115 result = { 116 'topic': topicdata.group(1) 117 } 118 else: 119 result = { 120 'usage': matchdata.group(1), 121 'desc': matchdata.group(2), 122 } 123 final_result[cmd] = result 124 out = json.dumps(final_result, indent=2) 125 destination = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cmds.json') 126 with open(destination, 'wb') as f: 127 f.write(out)
23 def create_json(): 24 final_obj["description"] = "titles from instructables" 25 final_obj["data"] = results 26 27 with open("instructables_titles.json", 'wt') as out: 28 json.dump(final_obj, out, sort_keys=True, indent=4, separators=(',', ': '))
55 def write_json(data, outfile): 56 with open(outfile, 'w') as data_file: 57 data_file.write(json.dumps(data, indent=4, sort_keys=True)) 58 data_file.write("\n")
36 def main(): 37 creds = {} 38 print('\nEnter your BaseSpace credentials') 39 creds['client_id'] = raw_input('Client ID: ') 40 if not creds['client_id']: 41 print('ERROR: Client ID is a required field.') 42 sys.exit(1) 43 creds['client_secret'] = raw_input('Client Secret: ') 44 if not creds['client_secret']: 45 print('ERROR: Client Secret is a required field.') 46 sys.exit(1) 47 creds['access_token'] = raw_input('Access Token: ') 48 if not creds['access_token']: 49 print('ERROR: Access Token is a required field.') 50 sys.exit(1) 51 print("\nThe following options should only be provided if you know what you're doing.") 52 print("If unsure, leave blank to use the default value.") 53 creds['api_server'] = raw_input('API Server [https://api.basespace.illumina.com/]: ') 54 if not creds['api_server'].strip(): 55 creds['api_server'] = 'https://api.basespace.illumina.com/' 56 creds['version'] = raw_input('Version [v1pre3]: ') 57 if not creds['version'].strip(): 58 creds['version'] = 'v1pre3' 59 write_cred_files(creds)
31 def write_to_json(path, data): 32 with open(path, 'w', newline='') as file: 33 file.write(json.dumps(data, indent=4))
15 def write_json(outfile, cache): 16 outdir = dirname(outfile) 17 if not exists(outdir): run_cmd("mkdir -p %s" % outdir) 18 ofile = open(outfile, 'w') 19 if ofile: 20 ofile.write(json.dumps(cache, sort_keys=True, indent=2,separators=(',',': '))) 21 ofile.close()
378 def writeJSONFile(wholeData, args): 379 path = os.path.dirname(args.exportFile) 380 ensurePath(path) 381 writeDict2JSON(wholeData, args.exportFile)
70 def main(): 71 try: 72 kwargs = json.load(sys.stdin) 73 except ValueError as exc: 74 finish(ok=False, error=str(exc)) 75 return 76 77 action = kwargs.pop("action", None) 78 if action == "start": 79 start(**kwargs) 80 elif action == "stop": 81 stop(**kwargs) 82 else: 83 finish(ok=False, error="Valid actions are 'start' and 'stop'")