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
If you have a Python object, you can convert it into a JSON string by using the json.dumps() method.
Discussions

converting JSON to string in Python - Stack Overflow
I did not explain my questions clearly at beginning. Try to use str() and json.dumps() when converting JSON to string in 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
Working with JSON in Python
Nice article. One minor, super-pedantic nit-pick: you keep using the words "JSON object", when you don't really mean that. A "JSON object" is merely one particular type a JSON string or text can hold, as defined by RFC7159 and its update RFC8259 , ECMA262 , ECMA404 , W3C, and various other standards. So you keep describing how to convert to/from "JSON object", when what you're really doing is converting to/from JSON string (which are also python strings) - and those strings actually are of JSON arrays in your examples, not JSON objects. The arrays happen to contain JSON objects inside the array. So for example this: json.dumps() takes in a Python data type and returns a JSON object. json.loads() takes in a JSON object and returns a Python data type. ...isn't actually true. For example just the two characters 42 is a perfectly valid JSON string, of just a JSON number type. Python's json.dumps() will accept a python int of 42 and convert it to a string. It will then take that serialized python/JSON string and convert it back to a simple python int, using json.loads(). There is no JSON object involved whatsoever. Again, I know I'm being pedantic. And I don't mean to criticize - the article's fine overall. I just get triggered by some minor details sometimes. :) More on reddit.com
🌐 r/Python
5
2
April 4, 2022
How Do I Get Python to Recognize this JSON string?
You're overriding the json module with a variable, here: json=soup.find_all('script') Call that variable literally anything else and you're golden More on reddit.com
🌐 r/learnpython
7
1
May 26, 2024
🌐
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 - This comes built-in to Python and is part of the standard library. So, say you have a file named demo.py. At the top you would add the following line: ... #include json library import json #json string data employee_string = '{"first_name": "Michael", "last_name": "Rodgers", "department": "Marketing"}' #check data type with type() method print(type(employee_string)) #output #<class 'str'>
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-json
Python JSON - GeeksforGeeks
December 23, 2025 - Let's see an example where we convert Python objects to JSON objects. Here json.dumps() function will convert a subset of Python objects into a JSON string.
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
1 month ago - For the most compact JSON, specify (',', ':') to eliminate whitespace. default (callable | None) – A function that is called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError. If None (the default), TypeError is raised. sort_keys (bool) – If True, dictionaries will be outputted sorted by key. Default False. Changed in version 3.2: Allow strings for indent in addition to integers.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-pretty-print-json
How to Pretty Print JSON in Python | DigitalOcean
September 16, 2025 - The json.dumps() method takes the JSON object and returns a JSON formatted string. The indent parameter defines the indent level for the formatted string. Let’s see what happens when we try to print a JSON file data.
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).

🌐
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 - Using the json.loads() method, we can deserialize native String, byte, or bytearray instance containing a JSON document to a Python dictionary.
🌐
Medium
medium.com › @blogshub4 › how-to-pretty-print-a-json-string-in-python-98a85f99ecb4
How to Pretty Print a JSON String in Python | by Blogshub | Medium
December 22, 2024 - Pretty Print JSON with Indentation: Use the json.dumps() method to convert the Python object back into a JSON string, and specify the indent parameter to define the level of indentation for readability.
🌐
KDnuggets
kdnuggets.com › convert-python-dict-to-json-a-tutorial-for-beginners
Convert Python Dict to JSON: A Tutorial for Beginners - KDnuggets
To convert a Python dictionary to JSON string, you can use the dumps() function from the json module. The dumps() function takes in a Python object and returns the JSON string representation.
🌐
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))
🌐
iProyal
iproyal.com › blog › python-string-to-json
How to Convert a Python String to JSON (Beginner’s Guide)
August 18, 2025 - Use `json.dumps()` to serialize a Python object into a JSON string.
🌐
Oreate AI
oreateai.com › blog › from-data-structures-to-strings-unpacking-json-conversion-in-python › be0b2c0900c33f8aa436ce7752f3aa58
From Data Structures to Strings: Unpacking JSON Conversion in Python - Oreate AI Blog
February 9, 2026 - Learn how to convert Python data structures into JSON strings using the `json.dumps()` function, ensuring compatibility for data exchange and storage.
🌐
Scaler
scaler.com › home › topics › string to json python
Convert String to JSON in Python - Scaler Topics
December 4, 2023 - This function accepts a Python object and produces a JSON string as its output. Decoding (deserializing) JSON: To change a JSON string into a Python object, the json.loads() function is used.
🌐
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!

🌐
Analytics Vidhya
analyticsvidhya.com › home › ways to convert string to json object
Ways to Convert String to JSON Object
March 21, 2024 - While literal_eval() offers security benefits, it may not be suitable for all scenarios, especially when dealing with complex JSON data. In such cases, json.loads() remains the preferred choice due to its broader support for handling JSON structures. The eval() function in Python can also be utilized to convert a string to a JSON object.
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - JSON, or JavaScript Object Notation, is a widely-used text-based format for data interchange. Its syntax resembles Python dictionaries but with some differences, such as using only double quotes for strings and lowercase for Boolean values. With built-in tools for validating syntax and manipulating JSON files, Python makes it straightforward to work with JSON data.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › convert json object to string in python
Convert JSON Object to String in Python - Spark By {Examples}
May 21, 2024 - Example 1: Let’s have a python dictionary with country details and convert this into json string. import json # Dictionary object representing as JSON country_json = { "Country Name": "US","States": ["California", "Texas","Ohio"],"Lakes_Available":"Yes"} # Json to string - Using json.dumps() country_string = json.dumps(country_json) print(country_string) print(type(country_string)) # Output: # {"Country Name": "US", "States": ["California", "Texas", "Ohio"], "Lakes_Available": "Yes"} #
🌐
W3Schools
w3schools.com › python › gloss_python_json_parse.asp
Python JSON Parse
If you have a JSON string, you can parse it by using the json.loads() method. The result will be a Python dictionary. ... import json # some JSON: x = '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x) # the result ...