Menu Close

How to convert JSON string to a dictionary not list with Python?

Sometimes, we want to convert JSON string to a dictionary not list with Python.

In this article, we’ll look at how to convert JSON string to a dictionary not list with Python.

How to convert JSON string to a dictionary not list with Python?

To convert JSON string to a dictionary not list with Python, we call json.loads with the JSON string string and get the value by the index of the JSON string is an array string.

For instance, we write

json1_data = json.loads(json1_str)[0]

to call json.loads with the json1_str JSON array string and get the first item in the returned list with [0].

Conclusion

To convert JSON string to a dictionary not list with Python, we call json.loads with the JSON string string and get the value by the index of the JSON string is an array string.

Posted in Python, Python Answers