Json2Yaml 使用 Python 将 Json 数据转换为 yaml 文件
This commit is contained in:
		
							parent
							
								
									ea0f1cda56
								
							
						
					
					
						commit
						75a705df05
					
				
							
								
								
									
										23
									
								
								tests/Json2Yaml.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								tests/Json2Yaml.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | ||||
| # Python script to Read file from JSON and convert to YAML | ||||
| # Author - HoneyMoose (https://www.ossez.com) | ||||
| 
 | ||||
| import json | ||||
| import ruamel.yaml as yaml | ||||
| 
 | ||||
| json_filename = 'resources/black_rock_test.json' | ||||
| yaml_filename = 'resources/black_rock_test.yaml' | ||||
| 
 | ||||
| # Read and process JSON | ||||
| with open(json_filename) as json_file: | ||||
|     data = json.load(json_file) | ||||
|     print(type(data)) | ||||
| 
 | ||||
|     for data_dict in data: | ||||
|         label_id = data_dict['label_id'] | ||||
|         print(str(label_id)) | ||||
| json_file.close() | ||||
| 
 | ||||
| # Write to YAML | ||||
| yaml_file = open(yaml_filename, 'w+') | ||||
| yaml.dump(data, yaml_file, allow_unicode=True) | ||||
| yaml_file.close() | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user