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
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-ways-to-convert-string-to-json-object
Convert String to JSON Object - Python - GeeksforGeeks
Let's explore different methods to do this efficiently. json.loads() method is the most commonly used function for parsing a JSON string and converting it into a Python dictionary.
Published: July 11, 2025
Discussions

convert a json string to python object - Stack Overflow
Is it possible to convert a json string (for e.g. the one returned from the twitter search json service) to simple string objects. Here is a small representation of data returned from the json serv... More on stackoverflow.com
๐ŸŒ stackoverflow.com
converting JSON to string in Python - Stack Overflow
str has absolutely nothing to do with JSON; the fact that str(somedict) looks sort of like JSON is coincidence. str gets a string representation of an object, which may look nothing like JSON (ex. for classes that implement __str__). ... Save this answer. ... Show activity on this post. json.dumps() is much more than just making a string out of a Python ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert from string to json python.
title: something funny This isn't JSON, but it might be YAML. You'll have to be clearer about what you're trying to do and what you've tried. Does anyone have an idea on how should I approach this? The point of Python's JSON library is that you don't work with JSON. You work with dictionaries, lists, and strings and then either convert into JSON (for transmission across some kind of socket, usually) or from JSON (when you're receiving it from something else, like an API.) but with no luck You really have to make an effort to be clearer. We're not sitting there looking over your shoulder; we don't know anything about the problem that you don't tell us. More on reddit.com
๐ŸŒ r/learnpython
8
1
May 5, 2019
How to convert following string to JSON in python - Stack Overflow
How can i convert the below string to JSON using python? str1 = "{'a':'1', 'b':'2'}" More on stackoverflow.com
๐ŸŒ stackoverflow.com
People also ask

Are there online platforms for string to JSON file Python conversions?
Numerous online platforms cater to string to JSON online conversions, but it's essential to remain cautious regarding data privacy when using third-party services.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ python json โ€“ how to convert a string to json
Python JSON โ€“ How to Convert a String to JSON: Guide & Examples
How do you differentiate between creating a JSON string and saving it as a file in Python?
While json.dumps results in a JSON formatted string, to inscribe this string as a file in Python, one requires additional file writing functions.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ python json โ€“ how to convert a string to json
Python JSON โ€“ How to Convert a String to JSON: Guide & Examples
How can one revert a JSON string back to its Python form?
The json.loads function in Python facilitates the decoding or deserialization of a JSON string back to its Python object form.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ python json โ€“ how to convert a string to json
Python JSON โ€“ How to Convert a String to JSON: Guide & Examples
๐ŸŒ
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 - // It defines the first name and last name of an employee ยท To use JSON with Python, you'll first need to include the JSON module at the top of your Python file. This comes built-in to Python and is part of the standard library.
๐ŸŒ
iProyal
iproyal.com โ€บ blog โ€บ python-string-to-json
How to Convert a Python String to JSON (Beginnerโ€™s Guide)
August 18, 2025 - Use `json.loads()` from the JSON module to convert a JSON string into a Python object (like a Python dictionary).
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_json.asp
Python JSON
Convert a Python object containing all the legal data types: import json x = { "name": "John", "age": 30, "married": True, "divorced": False, "children": ("Ann","Billy"), "pets": None, "cars": [ {"model": "BMW 230", "mpg": 27.5}, {"model": "Ford Edge", "mpg": 24.1} ] } print(json.dumps(x)) Try it Yourself ยป ยท The example above prints a JSON string, but it is not very easy to read, with no indentations and line breaks.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ string to json python
Convert String to JSON in Python - Scaler Topics
December 4, 2023 - The json module in Python provides a method called loads() which can be used to convert a JSON formatted string into a Python dictionary. This method is safe and widely used in Python applications. ... Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching โ‚น23L. ... The eval() function in Python evaluates the passed string as a Python expression and returns the result as a Python object...
Find elsewhere
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ ways to convert string to json object
Ways to Convert String to JSON Object
March 21, 2024 - We explored the functionalities of the json module, the ast module, the eval() function, the loads() function, and the fromstring() function. Through examples and explanations, we delved into how each method operates and compared their performance.
๐ŸŒ
TecAdmin
tecadmin.net โ€บ how-to-convert-string-to-json-in-python
How to Convert String to JSON in Python โ€“ TecAdmin
April 26, 2025 - The loads() method takes a JSON string as input and returns a Python object. The syntax is as follows: Here, json_string is the string that you want to convert to JSON, and json_object is the resulting Python object.
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ json-in-python
How to Convert a String to JSON in Python | LearnPython.com
The dumps() method converts a Python object to a JSON formatted string. We can also create a JSON file from data stored in a Python dictionary.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ python json โ€“ how to convert a string to json
Python JSON โ€“ How to Convert a String to JSON: Guide & Examples
April 21, 2026 - With built-in libraries, one can smoothly and reciprocally convert string to JSON Python. This tutorial is meticulously designed to walk you through encoding (serializing) and decoding (deserializing) processes in Python concerning JSON. Encoding, often referred to as serializing, is the methodological process of converting a Python object into a JSON string.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_convert_into_JSON.asp
Python Convert From Python to JSON
Remove List Duplicates Reverse ... ... If you have a Python object, you can convert it into a JSON string by using the json.dumps() method....
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python-ways-to-convert-string-to-json-object
How to Convert String to JSON using Python?
August 6, 2020 - The Python json.loads() function is used to convert the JSON-formatted string into a Python object.
Top answer
1 of 2
100

I've tried using simplejson.load() and json.load() but it gave me an error saying 'str' object has no attribute 'read'

To load from a string, use json.loads() (note the 's').

More efficiently, skip the step of reading the response into a string, and just pass the response to json.load().

2 of 2
1

if you don't know if the data will be a file or a string.... use

import StringIO as io
youMagicData={
results:[...],
"max_id":1346534,
"since_id":0,
"refresh_url":"?since_id=26202877001&q=twitter",
.
.
.
}

magicJsonData=json.loads(io.StringIO(str(youMagicData)))#this is where you need to fix
print magicJsonData
#viewing fron the center out...
#youMagicData{}>str()>fileObject>json.loads
#json.loads(io.StringIO(str(youMagicData))) works really fast in my program and it would work here so stop wasting both our reputation here and stop down voting because you have to read this twice 

from https://docs.python.org/3/library/io.html#text-i-o

json.loads from the python built-in libraries, json.loads requires a file object and does not check what it's passed so it still calls the read function on what you passed because the file object only gives up data when you call read(). So because the built-in string class does not have the read function we need a wrapper. So the StringIO.StringIO function in short, subclasses the string class and the file class and meshing the inner workings hears my low detail rebuild https://gist.github.com/fenderrex/843d25ff5b0970d7e90e6c1d7e4a06b1 so at the end of all that its like writing a ram file and jsoning it out in one line....

๐ŸŒ
Javatpoint
javatpoint.com โ€บ convert-string-to-json-in-python
Convert string to JSON in Python - Javatpoint
Convert string to JSON in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
Top answer
1 of 2
201

json.dumps() is much more than just making a string out of a Python object, it would always produce a valid JSON string (assuming everything inside the object is serializable) following the Type Conversion Table.

For instance, if one of the values is None, the str() would produce an invalid JSON which cannot be loaded:

>>> data = {'jsonKey': None}
>>> str(data)
"{'jsonKey': None}"
>>> json.loads(str(data))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 2 (char 1)

But the dumps() would convert None into null making a valid JSON string that can be loaded:

>>> import json
>>> data = {'jsonKey': None}
>>> json.dumps(data)
'{"jsonKey": null}'
>>> json.loads(json.dumps(data))
{u'jsonKey': None}
2 of 2
2

There are other differences. For instance, {'time': datetime.now()} cannot be serialized to JSON, but can be converted to string. You should use one of these tools depending on the purpose (i.e. will the result later be decoded).

๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ python โ€บ g4nr6w3u โ€บ python-parse-json-example
How to parse a JSON with Python?
To parse a JSON data string to a Python object, use the json.loads() method of the built-in package named json. The json.loads() method parses the provided JSON data string and returns a Python dictionary containing all the data from the JSON.
๐ŸŒ
W3Resource
w3resource.com โ€บ JSON โ€บ snippets โ€บ convert-string-to-json.php
Convert String to JSON in Python and JavaScript.
import json try: json_string = '{"name": "Jennigje", "age": 25, "skills": ["Python", "JavaScript"]' json_object = json.loads(json_string) except json.JSONDecodeError as e: print("Invalid JSON string:", e)
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ convert from string to json python.
r/learnpython on Reddit: Convert from string to json python.
May 5, 2019 -

Hello,

UPDATE:

The problem is that I need to change the convert the data from string type to JSON.

How I got to the respective string ?

I am writing out the data from a dict. (no, I cannot convert from dict to JSON due to the architecture of the code behind)

The dictionary has the following values in it:

('sid', 'something funny'), ('subtitle', 'Nothing yet'), ('date', 'Today'), ('weather': 'Hot')

Afterwards I do the following: (The data is required as a string)

for key in dicts:

data = data + key + ' : ' + result[key] + '\n'

Then I have to change from this

title: something funny

subtitle: Nothing yet

date: Today

weather: Hot

to this

{

'title': 'something funny',

'subtitle': 'Nothing yet',

'date': 'Today',

'weather': 'Hot',

}

So far I've tried some variation of the following (but with no luck):

json.dumps(data, separators=('\n', ': '), sort_keys=True)

Does anyone have an idea on how should I approach this?

Thanks in advance!

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-json-to-string
Convert JSON to string - Python - GeeksforGeeks
July 12, 2025 - This code creates a Python dictionary and converts it into a JSON string using json.dumps(). The result is printed along with its type, confirming that the output is now a string. ... import json # create a sample json a = {"name" : "GeeksforGeeks", "Topic" : "Json to String", "Method": 1} y = json.dumps(a) print(y) print(type(y))