json.load loads from a file-like object. You either want to use json.loads:

json.loads(data)

Or just use json.load on the request, which is a file-like object:

json.load(request)

Also, if you use the requests library, you can just do:

import requests

json = requests.get(url).json()
Answer from Blender on Stack Overflow
🌐
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.
Discussions

How can I parse (read) and use JSON in Python? - Stack Overflow
Beware that .load is for files; .loads is for strings. See also: Reading JSON from a file. Occasionally, a JSON document is intended to represent tabular data. If you have something like this and are trying to use it with Pandas, see Python - How to convert JSON File to Dataframe. More on stackoverflow.com
🌐 stackoverflow.com
Convert JSON string to dict using Python - Stack Overflow
The reputation requirement helps protect this question from spam and non-answer activity. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s... Release notes and bug fixes for beta.stackoverflow.com · 444 How can I parse (read) and use JSON in Python? 2 How to convert list of string ... More on stackoverflow.com
🌐 stackoverflow.com
Convert evaled string to JSON
I am getting a (suppossed to be) JSON string like this : (sJSON) { 'ARN': 'arn:aws:xxx:xxx:secret:xxx', 'Name': 'xxx/local', 'VersionId': 'xxx-xxx-xxx-xxx-xxx', 'SecretString': 'E:\\path\\to\\folder\\xxx.json', 'VersionStages': ['AWSCURRENT'], 'CreatedDate': datetime.datetime(2022, 9, 28, 8, ... More on discuss.python.org
🌐 discuss.python.org
0
0
September 28, 2022
easy way to extract json part of a string?
The correct move here is to edit the Powershell script to remove that output. That being said, consider that if you find the beginning of the JSON object, you can then pass the remaining string to json.loads. It will then raise a JSONDecodeError , which contains the position of where the error occured. So you slice the string one more time and try again. Result: import json def parse_json_garbage(s): s = s[next(idx for idx, c in enumerate(s) if c in "{["):] try: return json.loads(s) except json.JSONDecodeError as e: return json.loads(s[:e.pos]) In the REPL: >>> parse_json_garbage(""" ... this is a bunch of crap, ignore this please ... More crap ... ayylmao ... { ... "foo" : "bar", ... "baz" : "quux" ... } ... More crap goes here! ... """) {'foo': 'bar', 'baz': 'quux'} More on reddit.com
🌐 r/learnpython
12
2
January 12, 2022
People also ask

How to parse JSON strings in Python
To parse a JSON string in Python, we can use the built-in **`json`** module. This module provides two methods for working with JSON data: - **`json.loads()`** parses a JSON string and returns a Python object. - **`json.dumps()`** takes a Python object and returns a JSON string.
🌐
blog.apify.com
blog.apify.com › how-to-parse-json-with-python
How to parse JSON with Python
How to Read and Parse JSON files in Python
To parse a JSON file in Python, we can use the same json module we used in the previous section. The only difference is that instead of passing a JSON string to json.loads(), we pass the contents of a JSON file.
🌐
blog.apify.com
blog.apify.com › how-to-parse-json-with-python
How to parse JSON with Python
How to parse JSON with Python Pandas
To parse JSON with Python Pandas, we can use the pandas.read_json() function. This function can read JSON data into a pandas DataFrame, which allows for easy manipulation and analysis of the data.
🌐
blog.apify.com
blog.apify.com › how-to-parse-json-with-python
How to parse JSON with Python
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-loads-in-python
json.loads() in Python - GeeksforGeeks
Explanation: json.loads(s) parses the JSON string s and converts it into a Python dict.
Published   January 13, 2026
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
4 weeks ago - 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.
🌐
freeCodeCamp
freecodecamp.org › news › python-json-how-to-convert-a-string-to-json
Python JSON – How to Convert a String to JSON
November 9, 2021 - #include json library import json ...loyee_string)) #output #<class 'str'> you can turn it into JSON in Python using the json.loads() function....
🌐
Note.nkmk.me
note.nkmk.me › home › python
Load, Parse, Serialize JSON Files and Strings in Python | note.nkmk.me
August 6, 2023 - It is included in the standard library, so no additional installation is necessary. ... You can use json.loads() to convert JSON-formatted strings into Python objects, such as dictionaries.
Find elsewhere
🌐
Apify
blog.apify.com › how-to-parse-json-with-python
How to parse JSON with Python
March 11, 2025 - To extract JSON from a string in Python, you can use the json.loads() method.
🌐
ReqBin
reqbin.com › code › python › g4nr6w3u › python-parse-json-example
How to parse a JSON with Python?
To work with JSON in Python, you need to import the json module first, then call json.loads() method to parse the JSON string to a Python object.
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
July 6, 2023 - After loading JSON data into Python, you can access specific data elements using the keys provided in the JSON structure. In JSON, data is typically stored in either an array or an object. To access data within a JSON array, you can use array indexing, while to access data within an object, you can use key-value pairs. ... 1import json 2json_string ='{"numbers": [1, 2, 3], "car": {"model": "Model X", "year": 2022}}' 3json_data = json.loads(json_string) 4# Accessing JSON array elements using array indexing 5print(json_data['numbers'][0]) # Output: 1 6# Accessing JSON elements using keys 7print(
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - When you converted dog_registry to dog_json using json.dumps(), the integer key 1 became the string "1". When you used json.loads(), there was no way for Python to know that the string key should be an integer again. That’s why your dictionary key remained a string after deserialization. You’ll investigate a similar behavior by doing another conversion roundtrip with other Python data types! To explore how different data types behave in a roundtrip from Python to JSON and back, take a portion of the dog_data dictionary from a former section.
🌐
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 - This article demonstrates how to use Python’s json.load() and json.loads() methods to read JSON data from file and String. Using the json.load() and json.loads() method, you can turn JSON encoded/formatted data into Python Types this process ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-convert-string-to-json-object
Convert String to JSON Object - Python - GeeksforGeeks
Explanation: loads() function stands for "load string," and it parses the JSON string and converts it into a dictionary. This resulting dictionary is assigned to the variable res. ast.literal_eval() function safely evaluates a string containing ...
Published   July 11, 2025
🌐
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 - import json # JSON string json_string = '{"name": "Alice", "age": 30, "is_member": true}' # Convert JSON string to Python dictionary data = json.loads(json_string) print(data) # Output: {'name': 'Alice', 'age': 30, 'is_member': True} ... Purpose: ...
🌐
FavTutor
favtutor.com › blogs › read-write-and-parse-json-in-python
Read, Write and Parse JSON File in Python
October 14, 2023 - The method reads the contents of the file and converts it into a Python object, which we can then access and manipulate. The json.loads() method is used to parse a JSON string and convert it into a Python object.
🌐
GeeksforGeeks
geeksforgeeks.org › python › read-json-file-using-python
Read JSON file using Python - GeeksforGeeks
The Deserialization of JSON means the conversion of JSON objects into their respective Python objects. The load()/loads() method is used for it. If we have used JSON data from another program or obtained it as a string format of JSON, then it ...
Published   September 15, 2025
🌐
Python.org
discuss.python.org › python help
Convert evaled string to JSON - Python Help - Discussions on Python.org
September 28, 2022 - I am getting a (suppossed to be) JSON string like this : (sJSON) { 'ARN': 'arn:aws:xxx:xxx:secret:xxx', 'Name': 'xxx/local', 'VersionId': 'xxx-xxx-xxx-xxx-xxx', 'SecretString': 'E:\\path\\to\\folder\\xxx.json', 'VersionStages': ['AWSCURRENT'], ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python json.loads() method with examples
Python json.loads() Method with Examples - Spark By {Examples}
May 31, 2024 - The json.loads() is a method from the json module that is used to parse a JSON (JavaScript Object Notation) string and convert it into a Python object.
🌐
Reddit
reddit.com › r/learnpython › easy way to extract json part of a string?
r/learnpython on Reddit: easy way to extract json part of a string?
January 12, 2022 -

Hi

I have a string that contains a lot of text, and then a json part. Is there an easy way to extract only the json part? or is substring the way to go? (im just having truble with it cutting off some of the brackets).

The output is a powershell script, that looks up some data in a exchange server, and then outputs the object a json string. But it also outputs some text on how the script has run, so i want to remove that part. (i have been unable to supress that part)

Top answer
1 of 3
2
The correct move here is to edit the Powershell script to remove that output. That being said, consider that if you find the beginning of the JSON object, you can then pass the remaining string to json.loads. It will then raise a JSONDecodeError , which contains the position of where the error occured. So you slice the string one more time and try again. Result: import json def parse_json_garbage(s): s = s[next(idx for idx, c in enumerate(s) if c in "{["):] try: return json.loads(s) except json.JSONDecodeError as e: return json.loads(s[:e.pos]) In the REPL: >>> parse_json_garbage(""" ... this is a bunch of crap, ignore this please ... More crap ... ayylmao ... { ... "foo" : "bar", ... "baz" : "quux" ... } ... More crap goes here! ... """) {'foo': 'bar', 'baz': 'quux'}
2 of 3
2
It depends on the structure of the string. There is no good magic way for a function to look at a string and say "Hmmmm, this part is valid JSON," and toss the rest away. But if you, using your human intelligence, can identify a pattern in the output that is always true, then you can leverage that pattern to extract "the json part" and decode it. So say for instance that the script you're running has output like this: my-script.py Quote of the day: "The truth is rarely pure and never simple." -Oscar Wilde Weather: { "wind": "10 mph NNE", "clouds": null, "precipitation": null, "temperature": "47 Fahrenheit" } Winning lottery numbers: 3, 7, 22, 23, 41, 42, 43 Then you might say "Ah-ha, the valid JSON part starts after the string "Weather:" and ends just before the string "Winning lottery numbers". You might then write code that looks something like this: import json data = """ Quote of the day: "The truth is rarely pure and never simple." -Oscar Wilde Weather: { "wind": "10 mph NNE", "clouds": null, "precipitation": null, "temperature": "47 Fahrenheit" } Winning lottery numbers: 3, 7, 22, 23, 41, 42, 43 """ # Or however you're capturing the output of the script. start_pos = data.find('Weather:') + len('Weather:') # .find() will return the BEGINNING of the match, so you'll need to account for the length of the string you're searching for end_post = data.find('Winning lottery numbers') json_chunk = data[start_pos:end_pos] data_dictionary = json.loads(json_chunk) data_dictionary will then be a standard Python dictionary that you can you standard dictionary techniques to examine, print, change, write to disk, etc. When you're talking about breaking down terminal output, it's often easy to find a pattern that always applies in more or less the style above, though of course it's unlikely that you'll be dealing with output EXACTLY like that. If you can't, though, and you really just need to try paring down a string until it "looks like JSON," your problem is much harder, because "looks like JSON" is a human-type description that you'll have to find a way to translate into a form that the Python interpreter can understand.