The json.load() method (without "s" in "load") can read a file directly:

import json

with open('strings.json') as f:
    d = json.load(f)
    print(d)

You were using the json.loads() method, which is used for string arguments only.


The error you get with json.loads is a totally different problem. In that case, there is some invalid JSON content in that file. For that, I would recommend running the file through a JSON validator.

There are also solutions for fixing JSON like for example How do I automatically fix an invalid JSON string?.

Answer from ubomb on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ read-json-file-using-python
Read JSON file using Python - GeeksforGeeks
... import json with open('data.json', 'r') as file: data = json.load(file) print(json.dumps(data, indent=4)) ... In this example, we are reading data from the "data.json" file, and the output retains the same structured format as the original ...
Published ย  September 15, 2025
Discussions

Read a Windows path from a json file
So the user is pasting backslashes directly into the JSON file... ah. That's not valid JSON then, so you'll probably have to write a custom decoder? Luckily parsing JSON is not hard, but if you're having to do this then maybe it's time to rethink how you're doing configuration. Edit: YAML appears perfect for this, actually. In [1]: import json In [2]: import yaml In [3]: yaml.safe_load(r"'he\llo'") Out[3]: 'he\\llo' In [4]: json.loads(r'"he\llo"') JSONDecodeError: Invalid \escape: line 1 column 4 (char 3) Even better, YAML is a superset of JSON, so your users don't even need to learn a new format. You can keep using JSON-format config files and interpreting them using the yaml library. Edit 2: YAML doesn't interpret backslashes as escapes if it's a single-quoted string in the document. If it's double-quoted, you'll get the same error. More on reddit.com
๐ŸŒ r/learnpython
12
4
February 6, 2024
json - File path in python - Stack Overflow
I'm trying to load the json file but it gives me an error saying No such file or directory: with open ('folder1/sub1/sub2/sub2/sub3/file.json') as f: data = json.load(f) print data The above f... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How would I load a folder filled with Json files (same layout) and then extract the username field out?
The pathlib module import json from pathlib import Path for f in Path().rglob('*.json'): data = json.loads(f.read_text()) print(data['username']) More on reddit.com
๐ŸŒ r/learnpython
4
1
January 24, 2022
[AF] How to open static file, specifically json?
This is the only thing I have found to work, but it feels like a workaround. SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) json_url = os.path.join(SITE_ROOT, 'static', 'data.json') data = json.load(open(json_url)) SITE_ROOT evaluates to the fully qualified path to my project locally, i.e. /Users/me/...../app/static/data.json. If anyone has a better solution please let me know. More on reddit.com
๐ŸŒ r/flask
12
5
October 1, 2014
๐ŸŒ
Python.org
discuss.python.org โ€บ core development
Vote: New function for reading JSON from path - Core Development - Discussions on Python.org
March 10, 2021 - We have discussed about new function in the json module, but we didnโ€™t make decision about its naming. Previous discussion: Mailman 3 A shortcut to load a JSON file into a dict : json.loadf - Python-ideas - python.org Issue: Issue 43457: Include simple file loading and saving functions in ...
๐ŸŒ
GitHub
gist.github.com โ€บ tomschr โ€บ 86a8c6f52b81e35ac4723fef8435ec43
Read and write JSON files with pathlib.Path ยท GitHub
To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ยท Show hidden characters ยท Copy link ยท Copy Markdown ยท from pathlib import Path objects = json.loads(Path("some_source.json").read_text(encoding="UTF-8"), object_hook=blog_decode) Copy link ยท
๐ŸŒ
OneUptime
oneuptime.com โ€บ home โ€บ blog โ€บ how to read and write json files in python
How to Read and Write JSON Files in Python
January 25, 2026 - import json import os def ... first if not os.path.exists(filepath): print(f"Config file not found: {filepath}") return {} try: with open(filepath, 'r') as file: return json.load(file) except json.JSONDecodeError as e: ...
๐ŸŒ
Untitled Publication
cr88.hashnode.dev โ€บ using-pythons-pathlib-to-work-with-json-files-why-and-how
Using Python's pathlib to Work with JSON Files: Why and How?
September 16, 2023 - from pathlib import Path import json file_path = Path('C:/path/filename') content = file_path.read_text() data = json.loads(content) print(data) Here, file_path.read_text() reads the entire content of the specified JSON file and returns it as ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ read a windows path from a json file
r/learnpython on Reddit: Read a Windows path from a json file
February 6, 2024 -

I'm writing a script to automate some tasks for work, and I have it set up so that the user sets the inputs and other settings in a json file. One of the inputs is a user-specified Windows directory, and my intention is that the user will just paste it into the appropriate place in the json file. The problem is that Windows paths use the backslash character as a separator, which of course Python interprets as an escape. This causes an error just trying to read the json, so I can't even get it into my script to fix it there. In the interest of idiot-proofing the process to the extent possible, I want to avoid having the user do anything besides just paste (like change the slashes manually).

I have a workaround that uses an input prompt to get the directory from the user, but that seems clunky when all the other settings can be easily entered in the json file.

Any suggestions? Thanks.

Find elsewhere
๐ŸŒ
Canard Analytics
canardanalytics.com โ€บ blog โ€บ json-files-in-python
Working with JSON Files in Python | Canard Analytics
June 28, 2023 - Python converts a JSON object to a dictionary. json.load(filepath) to load a JSON file into Python as a dictionary.
๐ŸŒ
Medium
medium.com โ€บ @ryan_forrester_ โ€บ save-and-load-json-files-in-python-a-complete-guide-49a5760b8b49
Save and Load JSON Files in Python: A Complete Guide | by ryan | Medium
October 28, 2024 - def convert_to_serializable(obj): """Convert special Python types to JSON-serializable formats""" if isinstance(obj, (datetime, date)): return obj.isoformat() elif isinstance(obj, set): return list(obj) elif isinstance(obj, bytes): return obj.decode('utf-8') raise TypeError(f"Type {type(obj)} not serializable") # Usage example complex_data = { "date": datetime.now(), "tags": {"python", "json", "tutorial"}, "binary": b"Hello World" } with open("complex_data.json", "w") as file: json.dump(complex_data, file, default=convert_to_serializable) Remember: - Always use proper encoding - Handle special data types explicitly - Validate JSON before saving - Use appropriate error handling - Consider file permissions and paths
๐ŸŒ
Python Basics
pythonbasics.org โ€บ read-json-file
Reading JSON from a file - Python Tutorial
The python program below reads the json file and uses the values directly. The file can contain a one liner. The file content of example.json is: Save the file to example.json. ... The above program will open the file โ€˜example.jsonโ€™ and parse it. You can access the JSON data like any variables.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ json
Python JSON: Read, Write, Parse JSON (With Examples)
import json with open('path_to_file/person.json', 'r') as f: data = json.load(f) # Output: {'name': 'Bob', 'languages': ['English', 'French']} print(data) Here, we have used the open() function to read the json file. Then, the file is parsed using json.load() method which gives us a dictionary ...
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ hierarchical-and-structured-data-formats โ€บ lessons โ€บ parsing-json-files-in-python
Parsing JSON Files in Python
This process involves using Pythonโ€™s ... the json.load() function. The json module is preinstalled in Python, so there's no need to install any additional package. First, we need to open the file. We'll use a context manager (with statement) to ensure the file is properly closed after reading. Here, file_path is the path ...
๐ŸŒ
Codereview
codereview.doctor โ€บ features โ€บ python โ€บ best-practice โ€บ read-json-file-json-load
Use json.load to read a JSON file best practice | codereview.doctor
Python core developers are very careful about what features are included in the Python builtin modules, so it makes sense to utilise the convenience methods and not reinvent the wheel? For example, these result in the same outcome: with open('some/path.json', 'r') as f: content = json.load(f) with ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-read-json-file-in-python
How to read JSON file in Python
Suppose we have json file named "persons.json" with contents as shown in Example 2 above. We want to open and read it using python. This can be done in following steps ? ... Read the json file using load() and put the json data into a variable. Use the data retrieved from the file or simply ...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ reading-and-writing-json-to-a-file-in-python
Reading and Writing JSON to a File in Python
April 18, 2023 - In this guide, we'll take a look at how to read and write JSON data from and to a file in Python, using the json module.
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-loading-json-file
Python Loading JSON Files: A Comprehensive Guide - CodeRivers
April 5, 2025 - For example: import json def load_json_file(file_path): try: with open(file_path, 'r') as json_file: return json.load(json_file) except FileNotFoundError: print(f"The file {file_path} was not found.") return None except json.JSONDecodeError as e: print(f"Error decoding JSON in {file_path}: ...
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-json-load-from-file
Python JSON Load from File: A Comprehensive Guide - CodeRivers
January 24, 2025 - import json # Open the JSON file json_file = open('data.json', 'r') data = json.load(json_file) json_file.close() # Print the loaded data print(data) But this approach has a risk. If an exception occurs between opening the file and closing it, the file may not be properly closed, leading to ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ loading-a-json-file-in-python-how-to-read-and-parse-json
Loading a JSON File in Python โ€“ How to Read and Parse JSON
July 25, 2022 - Instead of using the read method of the file object and using the loads method of the json module, you can directly use the load method which reads and parses the file object.
๐ŸŒ
Studytonight
studytonight.com โ€บ python-howtos โ€บ how-to-read-json-file-in-python
How to read JSON file in Python - Studytonight
In the following example, we are going to read a JSON file and then print out the data. This json.load() function reads the string from the JSON file. The json.load(file) function creates and returns a new Python dictionary with the key-value ...