What is the difference between json.load and json.loads functions
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
json.load and json.loads both parse JSON into Python objects, but they do not take the same kind of input. The difference is short and important: json.load reads from a file-like object, while json.loads reads from a string, bytes, or bytearray.
json.load Reads From an Open File
Use json.load when you already have a file object:
Here, json.load reads the file contents for you and parses them into Python data structures such as dictionaries, lists, strings, and numbers.
This is the right choice when the JSON source lives on disk or comes from another file-like stream.
json.loads Parses a JSON String
Use json.loads when the JSON is already in memory as text:
Despite the similar name, loads does not mean "load from file." The trailing s stands for "string."
It is also valid for bytes and bytearray:
A Useful Way to Remember It
Think of the naming pairs:
- '
json.loadreads JSON from a stream' - '
json.loadsreads JSON from a string' - '
json.dumpwrites JSON to a stream' - '
json.dumpswrites JSON to a string'
The s forms work with strings. The versions without s work with file-like objects.
Practical Example: HTTP Versus File
If you fetch data from an HTTP client and already have the response text, use loads:
If you save the response to disk and later reopen the file, use load:
Both produce the same Python object. The only difference is where the JSON input starts from.
Common Errors
One common mistake is passing a filename string to json.load:
That fails because json.load expects a file object, not a path string. The correct form is:
Another mistake is passing an already opened file object to json.loads. That also fails because loads expects textual content, not a file handle.
Performance and Behavior Notes
For normal applications, choose based on input type, not performance. Internally, the main practical difference is still file object versus in-memory string.
If you already have the text in memory, loads avoids an unnecessary extra file step. If you are reading from disk, load keeps the code direct and readable.
In both cases, the parsed result is the same kind of Python object. The distinction is about where the JSON comes from, not about a special output format.
Common Pitfalls
The biggest mistake is thinking the s in loads means plural. It means string.
Another issue is mixing up file paths and file objects. A path like "config.json" is not the same thing as an opened handle returned by open(...).
A third problem is confusing parsing functions with serialization functions. load and loads parse JSON into Python objects, while dump and dumps go the other direction.
Summary
- '
json.load(f)parses JSON from an open file-like object.' - '
json.loads(text)parses JSON from a string,bytes, orbytearray.' - The trailing
smeans the function works with strings. - Use
dumpanddumpsfor the reverse direction, from Python objects to JSON. - Choose the function based on the kind of input you already have.

