Use json dumps() to convert a list to a JSON array in Python. The dumps() function takes a list as an argument and returns a JSON String.
json.dumps(obj)
Python list to JSON array example
Simple example code converting given list ["1", "2", "3"]
to a JSON array results in the string '["1", "2", "3"]'
.
For this example, you have to import a JSON module into the project file.
import json
aList = ["1", "2", "3"]
res = json.dumps(aList)
print(res)
print(type(res))
Output:
Do comment if you have any doubts or suggestions on this Python JSON and List topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.