Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: python extract zip file without directory structure 
Python :: python import from parent directory 
Python :: how to close a flask web server with python 
Python :: como comentar en Python? 
Python :: python to find the biggest among 3 numbers 
Python :: python pyowm 
Python :: python reference to back folder 
Python :: check how many times a substring appears in a string 
Python :: cd in python 
Python :: python lists as dataframe rows 
Python :: how to import your own function python 
Python :: print 2 decimal places python 
Python :: find duplicated entries present in a list 
Python :: add a button pyqt5 
Python :: how to define function in python 
Python :: pandas dict from row 
Python :: python path to python executable 
Python :: connect to spark cluster 
Python :: python filter dictionary by keys 
Python :: python count items in list 
Python :: deleting models with sqlalchemy orm 
Python :: python factorial 
Python :: get the name of a current script in python 
Python :: with suppress python 
Python :: Python3 boto3 put and put_object to s3 
Python :: how to make lists in python 
Python :: tqdm range python 
Python :: django in conda 
Python :: bucketizer pyspark 
Python :: django migrate model 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =