Created
November 9, 2015 20:21
-
-
Save mbrzusto/23fe728966247f25f3ec to your computer and use it in GitHub Desktop.
convert single quote json data file to double quote json data file (without mangling inner quotes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'mbrzustowicz' | |
# metadata.json has single quotes like this | |
# {'asin': 'B00M0AEPXG', 'imUrl': 'http://ecx.images-amazon.com/images/I/51hcXTUeHLL._BO2,204,203,200_ ..... } | |
# so the strategy is to read each line as a string, and dump into a REAL json file | |
import json | |
import ast | |
fr=open("/Users/mbrzustowicz/Downloads/metadata.json") | |
fw=open("/Users/mbrzustowicz/amazon_product_metadata.json", "w") | |
for line in fr: | |
json_dat = json.dumps(ast.literal_eval(line)) | |
dict_dat = json.loads(json_dat) | |
json.dump(dict_dat, fw) | |
fw.write("\n") | |
fw.close() | |
fr.close() |
Thank you so much!
Cool, Txs.
This should be a json module feature. That´s so easy 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much. I am working with Amazon product metadata (looks like you were too) and this worked great!