Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python replace double quotes with single quotes in string json loads

# Read in the file contents as text
with open('strings.json') as f:
    invalid_json = f.read()

# Replace all ' with "
valid_json = invalid_json.replace("'", '"')

# Verify that the JSON is valid now and this doesn't raise an exception
json.loads(valid_json)

# Save the modified text back to the file
with open('strings.json.fixed', 'w') as f:
    f.write(valid_json)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #replace #double #quotes #single #quotes #string #json #loads
ADD COMMENT
Topic
Name
5+3 =