Check if String is Valid JSON using Python

json.loads function and error handling

import json


def isJson(value):
    try:
        json.loads(value)
    except ValueError:
        return False
    return True


print(isJson('{"name":"John"}'))
print(isJson('{0,1,3}'))

Leave a Comment

Cancel reply

Your email address will not be published.