The Lib directory from the cPython 2.7.10 distribution. These files are unchanged and set the baseline for subsequent commits. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Daryl McDaniel <edk2-lists@mc2research.org> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18740 6f19259b-4bc3-4df7-8a09-765794883524
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| r"""Command-line tool to validate and pretty-print JSON
 | |
| 
 | |
| Usage::
 | |
| 
 | |
|     $ echo '{"json":"obj"}' | python -m json.tool
 | |
|     {
 | |
|         "json": "obj"
 | |
|     }
 | |
|     $ echo '{ 1.2:3.4}' | python -m json.tool
 | |
|     Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
 | |
| 
 | |
| """
 | |
| import sys
 | |
| import json
 | |
| 
 | |
| def main():
 | |
|     if len(sys.argv) == 1:
 | |
|         infile = sys.stdin
 | |
|         outfile = sys.stdout
 | |
|     elif len(sys.argv) == 2:
 | |
|         infile = open(sys.argv[1], 'rb')
 | |
|         outfile = sys.stdout
 | |
|     elif len(sys.argv) == 3:
 | |
|         infile = open(sys.argv[1], 'rb')
 | |
|         outfile = open(sys.argv[2], 'wb')
 | |
|     else:
 | |
|         raise SystemExit(sys.argv[0] + " [infile [outfile]]")
 | |
|     with infile:
 | |
|         try:
 | |
|             obj = json.load(infile)
 | |
|         except ValueError, e:
 | |
|             raise SystemExit(e)
 | |
|     with outfile:
 | |
|         json.dump(obj, outfile, sort_keys=True,
 | |
|                   indent=4, separators=(',', ': '))
 | |
|         outfile.write('\n')
 | |
| 
 | |
| 
 | |
| if __name__ == '__main__':
 | |
|     main()
 |