how to clean a JSON file and store it to another file in Python -
i trying read json file python. file described authors not strict json. in order convert strict json, suggest approach:
import json def parse(path): g = gzip.open(path, 'r') l in g: yield json.dumps(eval(l))
however, not being familiar python, able execute script not able produce output file new clean json. how should modify script in order produce new json file? have tried this:
import json class amazon(): def parse(self, inpath, outpath): g = open(inpath, 'r') out = open(outpath, 'w') l in g: yield json.dumps(eval(l), out) amazon = amazon() amazon.parse("original.json", "cleaned.json")
but output empty file. more welcome
import json class amazon(): def parse(self, inpath, outpath): g = open(inpath, 'r') open(outpath, 'w') fout: l in g: fout.write(json.dumps(eval(l))) amazon = amazon() amazon.parse("original.json", "cleaned.json")
Comments
Post a Comment