def main(): opt_parser = optparse.OptionParser( description='reformat json from stdin', version='Yajl-Py for Yajl %s' % yajl_version) opt_parser.add_option("-m", dest="beautify", action="store_false", default=True, help="minimize json rather than beautify (default)") opt_parser.add_option("-u", dest="dont_validate_strings", action='store_true', default=False, help="allow invalid UTF8 inside strings during parsing") opt_parser.add_option("-e", dest="escape_solidus", action='store_true', default=False, help="escape any forward slashes (for embedding in HTML)") opt_parser.add_option("-s", dest="stream", action='store_true', default=False, help="reformat a stream of multiple json entites") (options, args) = opt_parser.parse_args() # initialize the content handler (creates a Yajl Gen) ch = ReformatContentHandler( beautify=options.beautify, stream=options.stream, ) # initialize the parser yajl_parser = YajlParser(ch) yajl_parser.allow_comments = True # let's allow comments by default yajl_parser.allow_multiple_values = True yajl_parser.dont_validate_strings = options.dont_validate_strings yajl_parser.allow_multiple_values = options.stream yajl_parser.parse()
def main(args): parser = YajlParser(ContentHandler()) parser.allow_multiple_values = True if args: for fn in args: f = open(fn) parser.parse(f=f) f.close() else: parser.parse() return 0
def main(): opt_parser = optparse.OptionParser(description='reformat json from stdin', version='Yajl-Py for Yajl %s' % yajl_version) opt_parser.add_option("-m", dest="beautify", action="store_false", default=True, help="minimize json rather than beautify (default)") opt_parser.add_option( "-u", dest="dont_validate_strings", action='store_true', default=False, help="allow invalid UTF8 inside strings during parsing") opt_parser.add_option( "-e", dest="escape_solidus", action='store_true', default=False, help="escape any forward slashes (for embedding in HTML)") opt_parser.add_option("-s", dest="stream", action='store_true', default=False, help="reformat a stream of multiple json entites") (options, args) = opt_parser.parse_args() # initialize the content handler (creates a Yajl Gen) ch = ReformatContentHandler( beautify=options.beautify, stream=options.stream, ) # initialize the parser yajl_parser = YajlParser(ch) yajl_parser.allow_comments = True # let's allow comments by default yajl_parser.allow_multiple_values = True yajl_parser.dont_validate_strings = options.dont_validate_strings yajl_parser.allow_multiple_values = options.stream yajl_parser.parse()