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.

Answer from John Flatness on Stack Overflow
🌐
W3Schools
w3schools.com › PYTHON › python_json.asp
Python JSON
JSON is text, written with JavaScript object notation. Python has a built-in package called json, which can be used to work with JSON data.
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - A key-value pair in a JSON object is separated by a colon (:). On the left side of the colon, you define a key. A key is a string you must wrap in double quotes ("). Unlike Python, JSON strings don’t support single quotes (').
Discussions

How do I check if a string is valid JSON in Python? - Stack Overflow
In Python, is there a way to check if a string is valid JSON before trying to parse it? For example working with things like the Facebook Graph API, sometimes it returns JSON, sometimes it could More on stackoverflow.com
🌐 stackoverflow.com
What are JSON Files and why are they so useful in python - Stack Overflow
Please could you also tell me why ... every python book has them. Thanks. Edit: I have realized that this are other answers for this problem on stackoverflow which I didn't realize about when I made this quote. Sorry. I cannot delete this post anymore, since answers are already flowing in. ... JSON is just a way ... More on stackoverflow.com
🌐 stackoverflow.com
JSON Effectively is a Dictionary? Change My Mind
It’s essentially a mix of dictionaries and lists. A JSON object is similar to a dictionary, and a JSON array is similar to a list. Pretty much any JSON data structure can be translated into a complex Python data object. More on reddit.com
🌐 r/learnpython
7
0
June 10, 2022
Handling JSON files with ease in Python
Looks good. Considered discussing dataclasses/pydantic with json? I found that these go well together More on reddit.com
🌐 r/Python
55
421
May 29, 2022
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
2 weeks ago - In JSON, an object refers to any data wrapped in curly braces, similar to a Python dictionary. ... Be cautious when parsing JSON data from untrusted sources. A malicious JSON string may cause the decoder to consume considerable CPU and memory ...
🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - JSON serialization and deserialization are the processes of converting JSON data to and from other formats, such as Python objects or strings, to transmit or store the data. Serialization is the process of converting an object or data structure into a JSON string.
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-with-python
JSON with Python - GeeksforGeeks
July 23, 2025 - JSON (JavaScript Object Notation) is a file that is mainly used to store and transfer data mostly between a server and a web application. It is popularly used for representing structured data.
Top answer
1 of 8
343

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.

2 of 8
238

Example Python script returns a boolean if a string is valid json:

import json

def is_json(myjson):
  try:
    json.loads(myjson)
  except ValueError as e:
    return False
  return True

Which prints:

print is_json("{}")                          #prints True
print is_json("{asdf}")                      #prints False
print is_json('{ "age":100}')                #prints True
print is_json("{'age':100 }")                #prints False
print is_json("{\"age\":100 }")              #prints True
print is_json('{"age":100 }')                #prints True
print is_json('{"foo":[5,6.8],"foo":"bar"}') #prints True

Convert a JSON string to a Python dictionary:

import json
mydict = json.loads('{"foo":"bar"}')
print(mydict['foo'])    #prints bar

mylist = json.loads("[5,6,7]")
print(mylist)
[5, 6, 7]

Convert a python object to JSON string:

foo = {}
foo['gummy'] = 'bear'
print(json.dumps(foo))           #prints {"gummy": "bear"}

If you want access to low-level parsing, don't roll your own, use an existing library: http://www.json.org/

Great tutorial on python JSON module: https://pymotw.com/2/json/

Is String JSON and show syntax errors and error messages:

sudo cpan JSON::XS
echo '{"foo":[5,6.8],"foo":"bar" bar}' > myjson.json
json_xs -t none < myjson.json

Prints:

, or } expected while parsing object/hash, at character offset 28 (before "bar}
at /usr/local/bin/json_xs line 183, <STDIN> line 1.

json_xs is capable of syntax checking, parsing, prittifying, encoding, decoding and more:

https://metacpan.org/pod/json_xs

🌐
Medium
medium.com › data-science › working-with-json-data-in-python-45e25ff958ce
JSON in Python Tutorial | TDS Archive
August 11, 2021 - Imagine you build a program that creates data but you want also to share the data and the underlying information to other users/programs. This is why you want to take data and store it in a JSON formatted file. But how is data translated? I provide you with a conversion table for Python.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-json
Python JSON - GeeksforGeeks
December 23, 2025 - Python JSON (JavaScript Object Notation) is a data format for storing and transferring data, supported via the built-in json module for parsing, serializing and deserializing.
🌐
Programiz
programiz.com › python-programming › json
Python JSON: Read, Write, Parse JSON (With Examples)
Become a certified Python programmer. Try Programiz PRO! ... JSON (JavaScript Object Notation) is a popular data format used for representing structured data. It's common to transmit and receive data between a server and web application in JSON format.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-the-json-module-in-python
How to Use the JSON Module in Python – A Beginner's Guide
June 5, 2023 - JSON data is frequently expressed as nested dictionaries, lists, and scalar values such as texts, numbers, booleans, and null. It is named JSON because it closely mimics the syntax used in JavaScript objects.
🌐
W3Schools
w3schools.com › whatis › whatis_json.asp
What is JSON
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST · What is Roadmap What is HTTP What is HTML What is CSS What is Responsive What is JavaScript What is ES5 What is HTML DOM What is Google Maps What is Google Fonts What is Google Charts What is XML What is AJAX What is JSON What is CSS Icons What is Bootstrap What is W3.CSS What is CLI What is npm What is GitHub What is jQuery What is AngularJS What is React What is Vue.js What is W3.JS What is Front-End Dev.
🌐
Python Cheatsheet
pythoncheatsheet.org › home › modules › json module
Python JSON Module - Python Cheatsheet
JSON stands for JavaScript Object Notation and is a lightweight format for storing and transporting data. JSON is often used when data is sent from a server to a web page. Python has the built-in module json, which allow us to work with JSON data.
🌐
Nylas
nylas.com › developer how-tos › make use of json with python
Make Use of JSON With Python | Nylas
November 21, 2022 - In this post, we’ll look at what JSON is, how to consume it, and how to return your data in JSON format using Python.
🌐
Code Institute
codeinstitute.net › blog › python › working with json in python: a beginner’s guide
Working with JSON in Python: A Beginner's Guide - Code Institute Global
February 6, 2024 - Here, the `json.load()` function reads the content of the ‘person.json’ file and returns a Python object representing the JSON data. In this case, it will be a dictionary (`loaded_person`). You can then manipulate or display the loaded data as needed. When working with JSON data, readability is crucial.
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
July 6, 2023 - In the example above, there is an object 'car' inside the JSON structure that contains two mappings ('model' and 'year'). This is an example of a nested JSON structure where an object is contained within another object. Accessing elements within nested JSON structures requires using multiple keys or indices to traverse through the structure. JSON and Python objects Interchangeability
🌐
Bobdc
bobdc.com › blog › pythonjson
Parsing JSON with Python
December 15, 2024 - Springfield -- mydata properties: -- color amount arrayTest boolTest nullTest addressBookEntry -- list addressBookEntry property names and values: -- givenName: Richard familyName: Mutt address: {'street': '1 Main St', 'city': 'Springfield', 'zip': '10045'} There is a family name value. There is no phone value. I hope that someday when someone asks themselves, as I have asked myself every few months, “how do I deal with that little bit of JSON in Python again?” that this demo can save them a few minutes.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-parse-json-in-python-with-examples
How to Parse JSON in Python – A Complete Guide With Examples
October 29, 2025 - The JSON string starts with a square bracket, indicating an array at the root level. After parsing, products is a Python list containing three dictionaries.
🌐
Python Land
python.land › home › data processing with python › json in python: how to read, write, and parse
JSON in Python: How To Read, Write, and Parse • Python Land Tutorial
January 13, 2023 - JSON, short for JavaScript Object Notation, is an open standard. Although its name doesn’t imply so, it is a language-independent data format. With Python’s JSON library, we can read, write, and parse JSON to both store and exchange data using this versatile data format.