Skip to content

Convert Python list to JSON array | Example code

  • by

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:

Python list to JSON array

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.