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
🌐
Reddit
reddit.com › r/learnpython › json load() vs loads()
r/learnpython on Reddit: JSON load() vs loads()
November 30, 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

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.

🌐
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?
🌐
Medium
medium.com › @gadallah.hatem › the-difference-between-json-loads-and-json-load-2dbd30065f26
The difference between json.loads() and json.load() in Python | by Hatem A. Gad | Medium
December 15, 2024 - Parsing JSON files or streams. Example Input '{"key": "value"}' (string) File object (open('file.json')). Use json.loads() when the JSON data is already loaded as a string (e.g., from an API or raw text).
🌐
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.
🌐
Reddit
reddit.com › r/learnprogramming › json + python == confusion.
r/learnprogramming on Reddit: Json + python == confusion.
February 28, 2019 -

hey can anyone help me out here, my school gave me a json file, and I need to be able to read and write to and from that file in python, but I can't get it to work, and tutorials aren't really working out for me aswell. :(

https://github.com/DaanYouKnow/help
here is the file.

Top answer
1 of 5
8
We really need to see what code you have produced so far to attempt this. If you could post that as well it would be helpful. Without that there isn't much specific advice I can give. You need to be able to handle two things in order to achieve this; Python file operations (opening a file, writing to a file, reading from a file etc) JSON parsing (converting the JSON string into a useful data structure in your program) You can find more on file operations here; https://www.w3schools.com/python/python_file_handling.asp and you can use import json to get access to the JSON parsing library described here; https://www.w3schools.com/python/python_json.asp If you want more help, you will need to provide us with your code and state what specific problems you are having or errors you are getting.
2 of 5
1
Reading to and from JSON in python is quite easy. import json jsonfile = open("file.json") #this opens the file to read from, file.json but the name could be anything so long as it contains a valid json string jsoncontent = jsonfile.read() #this gets all the file contents into a string jsonfile.close() #you don't need it open right now jsoncontent = json.loads(jsoncontent) #this loads the json string into a python object that can be used. jsonitem = jsoncontent[0] #this gets the one or the entries to modify later, or you can just append() to the main jsoncontent you can then edit that as you would any other python dict to save changes: jsonstring = json.dumps(jsoncontent) #this turns a valid python object (list, dict) into a json string jsonfile = open("file.json","w") #using the w flag for writing #this opens the file again, this time in read mode jsonfile.write(jsonstring) #this saves the new json string into the file.
🌐
Quora
quora.com › What-is-the-usage-of-Json-load-and-JSON-loads-in-Python
What is the usage of Json.load and JSON.loads in Python? - Quora
Answer (1 of 2): The difference is in the source of the JSON text * [code ]json.load()[/code] expects to get the text from a file-like object * [code ]json.loads()[/code] expects to get its text from a string object Assume you have a file (json.txt) ...
🌐
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
🌐
Just Academy
justacademy.co › blog-detail › json-load-vs-loads
JSON LOAD VS loads
This function is used in Python to deserialize a JSON string into a Python dictionary object. It is used when you have a JSON string as input and you want to convert it into a dictionary or list of dictionaries. The ‘s’ in loads stands for ‘string’, as it takes a JSON string as input.
🌐
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 - 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. Using the json.loads() method, we can deserialize native String, byte, or bytearray instance containing a JSON document to a Python dictionary.
🌐
GeeksforGeeks
geeksforgeeks.org › python-difference-between-json-load-and-json-loads
Python - Difference Between json.load() and json.loads() - GeeksforGeeks
November 26, 2020 - 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.
🌐
Plain English
python.plainenglish.io › json-dumps-vs-json-dump-vs-json-loads-vs-json-load-in-python-99040c885c90
json.dumps VS json.dump VS json.loads VS json.load in Python | by Liu Zuo Lin | Python in Plain English
August 10, 2023 - Let’s say we have a JSON string. And we want to decode it, and convert it into a Python object (usually a list or dict) import json string = '{"apple": 4, "orange": 5, "pear": 6}' x = json.loads(string) print(x) # {'apple': 4, 'orange': 5, 'pear': 6} # x is a dict
🌐
Educative
educative.io › answers › what-is-the-difference-between-jsonloads-and-jsondumps
What is the difference between json.loads() and json.dumps()?
In summary, json.loads() converts JSON strings to Python objects, while json.dumps() converts Python objects to JSON strings. These functions are essential for handling JSON data within Python scripts, facilitating easy conversion and manipulation ...
🌐
Reddit
reddit.com › r/learnpython › unexpected behaviour of json loads
r/learnpython on Reddit: Unexpected behaviour of JSON loads
January 17, 2024 -

I'm trying to read a JSON message from an MQTT broker, and while testing, I'm sending all kinds of strings. I've noticed some weird behavior and was hoping someone could explain it to me.

When I enter a string with JSON format, it loads into a dictionary as expected: https://imgur.com/Li6oDMk

However, if I input another string, it triggers an error. I'm able to catch the error and handle it differently: https://imgur.com/GERjNGu

But here's where it gets interesting – if the string consists entirely of numbers (either integers or floats), the JSON.loads directly parses it to an int or float: https://imgur.com/K2LEZ9y

So, is there something wrong with my version, or is this the correct behavior?

🌐
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().
🌐
Srinimf
srinimf.com › 2023 › 01 › 23 › python-json-dump-vs-load-whats-the-difference
Python JSON Dump Vs. Load: What’s the Difference
November 1, 2023 - The JSON.load requires that the entire file is in standard JSON format, so if your file contains other information, you should load the JSON string first and parse it with loads rather than using load directly.
🌐
Python Forum
python-forum.io › thread-40905.html
JSON Dump and JSON Load
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...
🌐
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.