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
This error occurs when Python cannot locate the JSON file you are trying to read. Handling it prevents your program from crashing when the file is missing. ... import json try: with open('data.json', 'r') as file: data = json.load(file) print("File data =", data) except FileNotFoundError: print("Error: The file 'data.json' was not found.")
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 do I open or even find a json file?
You store python objects in a file and retrieve the objects from a file using the json module. This tutorial shows you the basics, and you can search for other tutorials. The python doc is here . More on reddit.com
๐ŸŒ r/learnpython
23
0
June 26, 2024
[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 JSON standard library.
๐ŸŒ
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 ยท
๐ŸŒ
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.

๐ŸŒ
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 - import json import time from pathlib import Path class APICache: def __init__(self, cache_file="api_cache.json"): self.cache_file = Path(cache_file) self.cache = self.load_cache() def load_cache(self): if self.cache_file.exists(): with open(self.cache_file, "r") as file: return json.load(file) return {} def save_cache(self): with open(self.cache_file, "w") as file: json.dump(self.cache, file) def get_data(self, key, max_age=3600): """Get data from cache if it's fresh, return None if expired""" if key in self.cache: entry = self.cache[key] if time.time() - entry["timestamp"] < max_age: return e
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Real Python
realpython.com โ€บ python-json
Working With JSON Data in Python โ€“ Real Python
August 20, 2025 - How can you read JSON data from a file into a Python program?Show/Hide ยท You can use the json.load() function to deserialize JSON data from a file into a Python object.
๐ŸŒ
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 file_path = Path('data')/'sample.json' Concise Reading: pathlib simplifies file reading. For instance, to read a text file, you can simply use: ... No need to use a with statement and open function for such a straightforward ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how do i open or even find a json file?
r/learnpython on Reddit: How do I open or even find a json file?
June 26, 2024 -

I'm making a text based rpg in python and i learnt that the data can be saved to a json file and then can be read from it and used. But how do I access that json file? Or maybe i should do another method to save game? Also is there a way to open a json file in python so that python can read it's values?

๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ json.html
JSON encoder and decoder โ€” Python 3.14.3 documentation
February 23, 2026 - fp can now be a binary file. The input encoding should be UTF-8, UTF-16 or UTF-32. Changed in version 3.11: The default parse_int of int() now limits the maximum length of the integer string via the interpreterโ€™s integer string conversion length limitation to help avoid denial of service attacks. json.loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)ยถ
๐ŸŒ
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 ...
๐ŸŒ
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 load_config(filepath): """Load JSON config file with proper error handling.""" # Check if file exists 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: print(f"Invalid JSON in {filepath}: {e}") return {} config = load_config('settings.json') ... import json # This JSON has a syntax error (trailing comma) bad_json = '{"name": "Alice", "age": 30,}' try: data = json.loads(bad_json) except json.JSONDecodeError as e: print(f"JSON parsin
๐ŸŒ
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 ...
๐ŸŒ
Codereview
codereview.doctor โ€บ features โ€บ python โ€บ best-practice โ€บ read-json-file-json-load
Use json.load to read a JSON file best practice | codereview.doctor
In fact, json.load is a wrapper around json.loads. It's a method provided out of the box by Python to simplify the task of reading JSON from file-like objects. 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 open('some/path.json', 'r') as f: content = json.loads(f.read())
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-38302.html
Reading Data from JSON
Hello looking to see if anyone could help me out here. Ive been trying to figure this out but seem to keep getting stuck. Im not very advance in python however im learning new things each day and time I write or try to write something new... Long st...
๐ŸŒ
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.
๐ŸŒ
Studytonight
studytonight.com โ€บ python-howtos โ€บ how-to-read-json-file-in-python
How to read JSON file in Python - Studytonight
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 pairs in the JSON file. Then, this dictionary is assigned to the data variable, and the ...