You can try to do json.loads()
, which will throw a ValueError
if the string you pass can’t be decoded as JSON.
In general, the “Pythonic” philosophy for this kind of situation is called EAFP, for Easier to Ask for Forgiveness than Permission.
More Related Contents:
- Check if a dictionary contain data true of false, then send a response back
- Why am I seeing “TypeError: string indices must be integers”?
- Convert JSON string to dict using Python
- Is there a memory efficient and fast way to load big JSON files?
- How to flatten a nested JSON recursively, with flatten_json
- Let JSON object accept bytes or let urlopen output strings
- String to Dictionary in Python [duplicate]
- Python – How to convert JSON File to Dataframe
- How to compare two JSON objects with the same elements in a different order equal?
- How to load all entries in an infinite scroll at once to parse the HTML in python
- Convert a python dict to a string and back
- Python json.loads fails with `ValueError: Invalid control character at: line 1 column 33 (char 33)`
- django-rest-framework 3.0 create or update in nested serializer
- Flask jsonify a list of objects
- Updates to JSON field don’t persist to DB
- How to dynamically build a JSON object?
- Retrieving JSON objects from a text file (using Python)
- Getting values from JSON using Python
- Python urllib2: Receive JSON response from url
- How can I parse (read) and use JSON in Python?
- OpenAI GPT-3 API error: “Cannot specify both model and engine”
- How to change json encoding behaviour for serializable python object?
- Python json.loads changes the order of the object
- Insert multiple documents in Elasticsearch – bulk doc formatter
- What is the difference between json.dumps and json.load? [closed]
- How to merge two json string in Python?
- json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 190) [duplicate]
- Issue with merging multiple JSON files in Python
- How to Fix JSON Key Values without double-quotes?
- Convert nested JSON to CSV file in Python