Skip to content

Commit

Permalink
Fix nestedtext-to-json.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Sep 28, 2020
1 parent f5736fd commit 9b60c36
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions examples/nestedtext-to-json
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ on_dup = de_dup if cmdline['--dedup'] else None
try:
if input_filename:
input_path = Path(input_filename)
nestedtext_content = input_path.read_text(encoding='utf-8')
else:
nestedtext_content = sys.stdin.read()
data = nt.load(input_filename, on_dup=de_dup)
json_content = json.dumps(data, indent=4)
if input_filename:
data = nt.load(input_path, on_dup=de_dup)
json_content = json.dumps(data, indent=4)
output_path = input_path.with_suffix('.json')
if output_path.exists():
if not cmdline['--force']:
fatal('file exists, use -f to force over-write.', culprit=output_path)
output_path.write_text(json_content, encoding='utf-8')
else:
data = nt.load(sys.stdin, on_dup=de_dup)
json_content = json.dumps(data, indent=4)
sys.stdout.write(json_content)
except OSError as e:
fatal(os_error(e))
Expand Down

0 comments on commit 9b60c36

Please sign in to comment.