1. Rami Al-Rfou
  2. fastavro

Commits

Miki Tebeka  committed 8ede364

default not pretty

  • Participants
  • Parent commits 09c269f
  • Branches default

Comments (0)

Files changed (2)

File fastavro/__main__.py

View file
  • Ignore whitespace
                         action='store_true', default=False)
     parser.add_argument('--version', action='version',
             version='fastavro {0}'.format(avro.__version__))
+    parser.add_argument('-p', '--pretty', help='pretty print json',
+                        action='store_true', default=False)
     args = parser.parse_args(argv[1:])
 
     if args.codecs:
             sys.stdout.write('\n')
             continue
 
+        indent = 4 if args.pretty else None
         try:
             for record in reader:
-                json_dump(record)
+                json_dump(record, indent)
                 sys.stdout.write('\n')
         except (IOError, KeyboardInterrupt):
             pass

File fastavro/six.py

View file
  • Ignore whitespace
     def py3_utob(n, encoding=_encoding):
         return bytes(n, encoding)
 
-    def json_dump(obj):
-        json.dump(obj, stdout, indent=4)
+    def json_dump(obj, indent):
+        json.dump(obj, stdout, indent=indent)
 
 else:  # Python 2x
     from cStringIO import StringIO as MemoryIO
         return n
 
     _outenc = getattr(stdout, 'encoding', _encoding)
-    def json_dump(obj):
-        json.dump(obj, stdout, indent=4, encoding=_outenc)
+    def json_dump(obj, indent):
+        json.dump(obj, stdout, indent=indent, encoding=_outenc)
 
 # We do it this way and not just redifine function since Cython do not like it
 if sys.version_info >= (3, 0):