Skip to content

Commit d13fc06

Browse files
author
Bernardas Ališauskas
committed
add jl-to-json
1 parent e0c414d commit d13fc06

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

jl-to-json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
"""
3+
simple jsonlines to json converted
4+
usage: jl-to-json foo.jl > foo.json
5+
6+
License: GPLv3
7+
Author: Bernardas Ališauskas <[email protected]>
8+
"""
9+
import json
10+
11+
import click
12+
from click import echo
13+
14+
15+
@click.command()
16+
@click.argument('file', type=click.File('r'))
17+
@click.argument('key', default='id')
18+
def main(file, key):
19+
"""
20+
simple jsonlines to json converted
21+
usage: jl-to-json foo.jl > foo.json
22+
"""
23+
data = {}
24+
for line in file:
25+
d = json.loads(line)
26+
data[d[key]] = d
27+
echo(json.dumps(data, ensure_ascii=False))
28+
29+
30+
if __name__ == '__main__':
31+
main()

0 commit comments

Comments
 (0)