3 # Reads an array of JSON objects and writes out CSV-format,
4 # with key names in first row.
5 # Columns will be union of all keys in the objects.
12 json_string = sys.stdin.read()
13 json_array = json.loads(json_string)
16 for item in json_array:
17 columns.update(set(item))
19 writer = csv.writer(sys.stdout)
20 writer.writerow(list(columns))
21 for item in json_array:
24 if c in item: row.append(str(item[c]))