Yes, s stands for string. The json.loads function does not take the file path, but the file contents as a string. Look at the documentation.

Simple example:

with open("file.json") as f:
  data = json.load(f)  # ok

  data = json.loads(f)  # not ok, f is not a string but a file
text = '{"a": 1, "b": 2}'  # a string with json encoded data
data = json.loads(text) 
Answer from Gijs on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-difference-between-json-load-and-json-loads
Difference Between json.load() and json.loads() - Python - GeeksforGeeks
July 3, 2025 - json.load() takes a file object and returns the json object. It is used to read JSON encoded data from a file and convert it into a Python dictionary and deserialize a file itself i.e.
Top answer
1 of 6
306

Yes, s stands for string. The json.loads function does not take the file path, but the file contents as a string. Look at the documentation.

Simple example:

with open("file.json") as f:
  data = json.load(f)  # ok

  data = json.loads(f)  # not ok, f is not a string but a file
text = '{"a": 1, "b": 2}'  # a string with json encoded data
data = json.loads(text) 
2 of 6
138

Just going to add a simple example to what everyone has explained,

json.load()

json.load can deserialize a file itself i.e. it accepts a file object, for example,

# open a json file for reading and print content using json.load
with open("/xyz/json_data.json", "r") as content:
  print(json.load(content))

will output,

{u'event': {u'id': u'5206c7e2-da67-42da-9341-6ea403c632c7', u'name': u'Sufiyan Ghori'}}

If I use json.loads to open a file instead,

# you cannot use json.loads on file object
with open("json_data.json", "r") as content:
  print(json.loads(content))

I would get this error:

TypeError: expected string or buffer

json.loads()

json.loads() deserialize string.

So in order to use json.loads I will have to pass the content of the file using read() function, for example,

using content.read() with json.loads() return content of the file,

with open("json_data.json", "r") as content:
  print(json.loads(content.read()))

Output,

{u'event': {u'id': u'5206c7e2-da67-42da-9341-6ea403c632c7', u'name': u'Sufiyan Ghori'}}

That's because type of content.read() is string, i.e. <type 'str'>

If I use json.load() with content.read(), I will get error,

with open("json_data.json", "r") as content:
  print(json.load(content.read()))

Gives,

AttributeError: 'str' object has no attribute 'read'

So, now you know json.load deserialze file and json.loads deserialize a string.

Another example,

sys.stdin return file object, so if i do print(json.load(sys.stdin)), I will get actual json data,

cat json_data.json | ./test.py

{u'event': {u'id': u'5206c7e2-da67-42da-9341-6ea403c632c7', u'name': u'Sufiyan Ghori'}}

If I want to use json.loads(), I would do print(json.loads(sys.stdin.read())) instead.

Discussions

Stdlib json.load[s]() return type - Typing - Discussions on Python.org
The json.load and json.loads both return typing.Any but why? Shouldn’t they be dict[str, Any]? Reference: typeshed/stdlib/json/__init__.pyi at main · python/typeshed · GitHub More on discuss.python.org
🌐 discuss.python.org
0
October 13, 2024
Why json.dump() and .load() are really needed?
JSON data in python is essentially a dictionary (at least they are interchangeable, there are some minor differences with the formatting). Have you tried saving a dictionary to a simple text file? my_data = { 'a': [1, 2, 3], 'b': {'foo': 'bar', 'baz': [4, 5, 6]} } with open('test_file.txt', 'w') as file: file.write(my_data) This is not possible because Python expects a string that it can write to a file. It doesn't know how to turn a dictionary into something it can write to a file. But, maybe you then do this instead: my_data = { "a": [1, 2, 3], "b": {"foo": "bar", "baz": [4, 5, 6]} } with open('test_file.txt', 'w') as file: # cast my_data to a string first file.write(str(my_data)) And it works. But what if you want to read that file? with open('test_file.txt', 'r') as file: read_data = file.read() Now you have a problem, because your output is this string: "{'a': [1, 2, 3], 'b': {'foo': 'bar', 'baz': [4, 5, 6]}}" How do you convert a string into a dictionary? This here doesn't work: with open('test_file.txt', 'r') as file: read_data = dict(file.read()) Python by itself does not know how to convert a string into a dictionary. For that you need JSON. Also it makes sure that you meet all the conventions of the JSON format so that you can exchange data between different languages (e.g. from Python to JavaScript). The other thing is, if you have a .txt file, how would anybody know that this file contains a data structure without opening the file? If the file extension says "JSON" everybody knows how to interpret the data. Same with .XML, .HTML etc. More on reddit.com
🌐 r/learnpython
18
8
October 15, 2020
JSON load() vs loads()

load() loads JSON from a file or file-like object

loads() loads JSON from a given string or unicode object

It's in the documentation

More on reddit.com
🌐 r/learnpython
7
6
December 2, 2013
Efficiently Load Large JSON Files Object by Object
What structures did you test with? I imagine this would be very useful for a JSON that's a long list of items... Does this also help for a file that is one big object? (I assume not?) How about nested lists? More on reddit.com
🌐 r/Python
2
0
August 4, 2023
🌐
Reddit
reddit.com › r/learnpython › json load() vs loads()
r/learnpython on Reddit: JSON load() vs loads()
December 2, 2013 -

Can someone explain what the difference is between using either load() or loads() is with the JSON library? And which, if either, is the preferred method.

I'm writing a simple script where I want the JSON data from a URL parsed out into a list. Both of these options seem to work:

import json
import urllib2

url = "string to url"

response = urllib2.urlopen(url)
data = json.load(response)

or

import json
import urllib2

url = "string to url"

response = urllib2.urlopen(url)
data = json.loads(response.read())

I know that there are other libraries available for parsing out JSON data, but for the time being I'm working only with the json and urllib2 libraries.

Any insight into which one should be used?

Thanks

🌐
Medium
medium.com › @gadallah.hatem › the-difference-between-json-loads-and-json-load-2dbd30065f26
The difference between json.loads() and ...
December 15, 2024 - Feature json.loads() json.load() Input JSON string (in memory). File object or stream (on disk or in memory). Output Python object (dict, list, etc.). Python object (dict, list, etc.). Use Case Parsing JSON strings (e.g., API responses). Parsing JSON files or streams.
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
2 weeks ago - When a dictionary is converted into JSON, all the keys of the dictionary are coerced to strings. As a result of this, if a dictionary is converted into JSON and then back into a dictionary, the dictionary may not equal the original one. That is, loads(dumps(x)) != x if x has non-string keys.
🌐
Medium
medium.com › snowflake › json-methods-load-vs-loads-and-dump-vs-dumps-21434a520b17
JSON Methods: load vs loads() and dump vs dumps() | by Sachin Mittal | Snowflake Builders Blog: Data Engineers, App Developers, AI, & Data Science | Medium
May 2, 2022 - Json.loads(): to convert JSON string to a dictionary. Sometimes we receive JSON response in string format. So to use it in our application, we need to convert JSON string into a Python dictionary.
Find elsewhere
🌐
PYnative
pynative.com › home › python › json › python json parsing using json.load() and loads()
Python JSON Parsing using json.load() and loads()
May 14, 2021 - Python built-in module json provides the following two methods to decode JSON data. ... To parse JSON from URL or file, use json.load().
🌐
Just Academy
justacademy.co › blog-detail › json-load-vs-loads
JSON LOAD VS loads
May 7, 2024 - json.load is more straightforward when you want to quickly load the entire JSON content from a file without much preprocessing. ... Suppose you are developing a training program for students to learn JSON manipulation in Python.
🌐
Oreate AI
oreateai.com › blog › understanding-jsonload-vs-jsonloads-in-python › 90ebefc58481fbca189962dece43d86a
Understanding json.load vs. json.loads in Python - Oreate AI Blog
January 15, 2026 - On the other hand, we have json.loads, which stands for “load string.” This method takes a string formatted as JSON rather than reading from an external source like a file. It’s particularly useful when you receive JSON data as part of ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › orjson-loads-vs-json-loads-in-python
json.loads() vs json.loads() in Python - GeeksforGeeks
July 23, 2025 - In this example, below Python code compares the performance of the standard json library and the optimized orjson library for encoding and decoding JSON data. It first loads JSON data from a file, measures the time taken to decode the data using json.loads(), and then does the same using orjson.loads().
🌐
Python.org
discuss.python.org › typing
Stdlib json.load[s]() return type - Typing - Discussions on Python.org
October 13, 2024 - The json.load and json.loads both return typing.Any but why? Shouldn’t they be dict[str, Any]? Reference: typeshed/stdlib/json/__init__.pyi at main · python/typeshed · GitHub
🌐
Reddit
reddit.com › r/learnpython › why json.dump() and .load() are really needed?
r/learnpython on Reddit: Why json.dump() and .load() are really needed?
October 15, 2020 -

Hi, hope everyone is well.

Just nearing the basics end of PCC book, I'm at saving user's data now. What exactly is the reason, when storing simple data, to use json.dump() or load(), instead of just saving and then reading it from simple text file?

I just can't place it in my head why do I really need it and it always makes it more difficult for me to learn if that's the case.

Thank you all in advance.

Top answer
1 of 8
6
JSON data in python is essentially a dictionary (at least they are interchangeable, there are some minor differences with the formatting). Have you tried saving a dictionary to a simple text file? my_data = { 'a': [1, 2, 3], 'b': {'foo': 'bar', 'baz': [4, 5, 6]} } with open('test_file.txt', 'w') as file: file.write(my_data) This is not possible because Python expects a string that it can write to a file. It doesn't know how to turn a dictionary into something it can write to a file. But, maybe you then do this instead: my_data = { "a": [1, 2, 3], "b": {"foo": "bar", "baz": [4, 5, 6]} } with open('test_file.txt', 'w') as file: # cast my_data to a string first file.write(str(my_data)) And it works. But what if you want to read that file? with open('test_file.txt', 'r') as file: read_data = file.read() Now you have a problem, because your output is this string: "{'a': [1, 2, 3], 'b': {'foo': 'bar', 'baz': [4, 5, 6]}}" How do you convert a string into a dictionary? This here doesn't work: with open('test_file.txt', 'r') as file: read_data = dict(file.read()) Python by itself does not know how to convert a string into a dictionary. For that you need JSON. Also it makes sure that you meet all the conventions of the JSON format so that you can exchange data between different languages (e.g. from Python to JavaScript). The other thing is, if you have a .txt file, how would anybody know that this file contains a data structure without opening the file? If the file extension says "JSON" everybody knows how to interpret the data. Same with .XML, .HTML etc.
2 of 8
3
How would you structure the text file so that you can load the data later?
🌐
Python Forum
python-forum.io › thread-40905.html
JSON Dump and JSON Load
October 12, 2023 - I apologize, the insert code snippet button isn't working. I am having an issue dumping to json and then reading back in. When I read it back in correctly. In the screenshot you can see visual studio indicating the object is slightly different and w...
🌐
Analytics Vidhya
analyticsvidhya.com › home › python json.loads() and json.dump() methods
Python json.loads() and json.dump() methods - Analytics Vidhya
May 1, 2025 - The json.loads() function automatically converts JSON data types to their corresponding Python data types. For example, JSON strings are converted to Python strings, JSON numbers are converted to Python integers or floats, and JSON arrays are converted to Python lists.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Python has a built-in package called json, which can be used to work with JSON data. ... If you have a JSON string, you can parse it by using the json.loads() method.
🌐
Programiz
programiz.com › python-programming › json
Python JSON: Read, Write, Parse JSON (With Examples)
To work with JSON (string, or file containing JSON object), you can use Python's json module. You need to import the module before you can use it. ... The json module makes it easy to parse JSON strings and files containing JSON object. You can parse a JSON string using json.loads() method.
🌐
Imperial College London
python.pages.doc.ic.ac.uk › java › lessons › java › 10-files › 03-load.html
Python for Java Programmers > Loading JSON files
To load your object directly from a JSON string rather than a file, use json.loads(string) (loads is short for ‘load string’). import json json_string = '[{"id": 2, "name": "Basilisk"}, {"id": 6, "name": "Nagaraja"}]' data = json.loads(json_string) print(data[0]) # {'id': 2, 'name': 'Basilisk'} ...
🌐
Codecademy
codecademy.com › docs › python › json module › .load()
Python | JSON Module | .load() | Codecademy
May 29, 2025 - The .load() method in Python’s JSON module is used to parse JSON data from a file-like object and convert it into a Python object. This method reads JSON content directly from files, such as .json files, and transforms the structured data into native Python data types like dictionaries, lists, strings, numbers, and booleans.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Load, Parse, Serialize JSON Files and Strings in Python | note.nkmk.me
August 6, 2023 - You can use json.load() to load JSON files into Python objects, such as dictionaries.