List to json Python

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 and suggestions on this Python JSON and List topic.

Note: IDE:PyCharm2021.3 [Community Edition]

Windows 10

Python 3.10.1

AllPython Examplesare inPython3, so Maybe its different from python 2 or upgraded versions.

Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.

Share this:

  • Facebook
  • WhatsApp
  • LinkedIn
  • More

  • Twitter
  • Print
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • Skype
  • Email

Related

Video liên quan

Chủ Đề