Skip to content

Commit

Permalink
sort keys
Browse files Browse the repository at this point in the history
  • Loading branch information
adasium committed Mar 5, 2024
1 parent 3c4ca8d commit 573b4cb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bin/chom_json2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import csv
import collections
import json
import sys
import argparse
Expand Down Expand Up @@ -122,10 +123,10 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
args = parser.parse_args()
if args.debug:
print(args.columns)
data = json.load(sys.stdin)
json_fields = set()
data = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict)
json_fields = []
for doc in data:
json_fields |= set(doc)
json_fields = list(dict.fromkeys(json_fields + list(doc.keys())))

csv_columns = args.columns or json_fields
print(','.join(csv_columns))
Expand Down

0 comments on commit 573b4cb

Please sign in to comment.