def main(invocation, *cli_args):
    json_src = stdin
    if (len(cli_args) > 0):
        json_src = cfopen(cli_args[0], 'r', 'utf-8')
    data = json.load(json_src, 'utf-8')
    json_enc = dict(indent=2, sort_keys=True)
    json_enc['separators'] = (',', ': ')
    rules = data.get('entries')
    if (rules is not None):
        del data['entries']
    json_enc = json.JSONEncoder(**json_enc)
    json_iter = json_enc.iterencode(data)
    for chunk in json_iter:
        chunk = chunk.lstrip()
        if (chunk == ''):
            continue
        if chunk.startswith('"'):
            stdout.write(' ')
            if (rules is not None):
                stdout.write('"entries": {\n')
                verbsep = '  '
                for verb in sorted(rules.keys()):
                    stdout.write(((verbsep + json.dumps(verb)) + ': ['))
                    write_rule_subjs(stdout, rules[verb])
                    stdout.write(']')
                    verbsep = ',\n  '
                stdout.write('\n}, ')
            stdout.write(chunk)
            break
        stdout.write(chunk)
    for chunk in json_iter:
        if (rules is not None):
            if chunk.startswith(','):
                stdout.write(',')
                chunk = chunk[1:]
            if chunk.startswith('\n'):
                chunk = (' ' + chunk.lstrip())
        stdout.write(chunk)
    stdout.write('\n')
def main(invocation, *cli_args):
    json_src = stdin
    if (len(cli_args) > 0):
        json_src = cfopen(cli_args[0], 'r', 'utf-8')
    data = json.load(json_src, 'utf-8')
    json_enc = dict(indent=2, sort_keys=True)
    json_enc['separators'] = (',', ': ')
    rules = data.get('entries')
    if (rules is not None):
        del data['entries']
    json_enc = json.JSONEncoder(**json_enc)
    json_iter = json_enc.iterencode(data)
    for chunk in json_iter:
        chunk = chunk.lstrip()
        if (chunk == ):
            continue
        if chunk.startswith('"'):
            stdout.write(' ')
            if (rules is not None):
                stdout.write('"entries": {\n')
                verbsep = '  '
                for verb in sorted(rules.keys()):
                    stdout.write(((verbsep + json.dumps(verb)) + ': ['))
                    write_rule_subjs(stdout, rules[verb])
                    stdout.write(']')
                    verbsep = ',\n  '
                stdout.write('\n}, ')
            stdout.write(chunk)
            break
        stdout.write(chunk)
    for chunk in json_iter:
        if (rules is not None):
            if chunk.startswith(','):
                stdout.write(',')
                chunk = chunk[1:]
            if chunk.startswith('\n'):
                chunk = (' ' + chunk.lstrip())
        stdout.write(chunk)
    stdout.write('\n')