Skip to content

Instantly share code, notes, and snippets.

@FMNSSun
Last active Apr 12, 2016
Embed
What would you like to do?
Convert json array to newline separated
#
#- arr2nljson
# munt, 2016
#
# Reads in a JSON array and outputs new-line
# separated documents
#
#
import sys
import json
p_fin = sys.argv[1]
p_fout = sys.argv[2]
print("Input: " + p_fin)
print("Output: " + p_fout)
print("Opening files...")
fin = open(p_fin, "r")
fout = open(p_fout, "w")
print("Reading input...")
data = fin.read()
print("Loading json...")
json_data = json.loads(data)
n = 0
print("Writing json...")
for entry in json_data:
fout.write(json.dumps(entry, sort_keys = True) + "\n")
n += 1
print("Closing files...")
fin.close()
fout.close()
print("Done...")
print("Wrote " + str(n) + " entries.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment