Use the json module to produce JSON output:

import json

with open(outputfilename, 'wb') as outfile:
    json.dump(row, outfile)

This writes the JSON result directly to the file (replacing any previous content if the file already existed).

If you need the JSON result string in Python itself, use json.dumps() (added s, for 'string'):

json_string = json.dumps(row)

The L is just Python syntax for a long integer value; the json library knows how to handle those values, no L will be written.

Demo string output:

>>> import json
>>> row = [1L,[0.1,0.2],[[1234L,1],[134L,2]]]
>>> json.dumps(row)
'[1, [0.1, 0.2], [[1234, 1], [134, 2]]]'
Answer from Martijn Pieters on Stack Overflow
🌐
W3Schools
w3schools.com › python › gloss_python_convert_into_JSON.asp
Python Convert From Python to JSON
If you have a Python object, you can convert it into a JSON string by using the json.dumps() method.
Discussions

Creating JSON Array of data with python
What I’m trying to do: I’m trying to retrieve the data from database and then create a JSON Array to send it to Google Gantt. What I’ve tried and what’s not working: I’m having propably problems with the conversion of python date to JSON date. Really I’m out of ideas how to do it ... More on anvil.works
🌐 anvil.works
1
0
August 22, 2023
How to convert nested list into JSON?
json.dumps can handle nested data structures, too. More on reddit.com
🌐 r/learnpython
6
3
June 23, 2018
Extremely confused with parsing a JSON array
data['types'] is a list. data['types'] == "['route']" is treating it as if it was a string, so that's never going to be true. As soon as json.load() returns, the JSON is parsed. It is no more. What you've got at that point is a pure Python data structure, not JSON. The brackets and braces and quotes do not exist any more. So data['types'] is a list of strings. If you want to see if a list contains a given string, use the in operator: if 'route' in data['types']: ... I also suggest being a bit more careful with your naming conventions. You're reusing the name address to refer to multiple things. json.load() expects a file-like object. json.loads() expects a string. I don't know what reader() is, but apparently it returns a StreamReader object which is a file-like object, which is why it does not work to pass that to json.loads(). More on reddit.com
🌐 r/learnpython
4
2
April 14, 2017
Unable to append data to Json array object with desired output
I’m tried getting help for same issue on stack-overflow but got no help or replies. I’m re-posting here with the hope that someone can please guide me as I’m unable to push the code to repository due to delay. My code import json import re from http.client import responses import vt import ... More on discuss.python.org
🌐 discuss.python.org
5
0
January 18, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-python-list-to-json
Convert Python List to Json - GeeksforGeeks
July 23, 2025 - In this example, a Python list containing a mix of integers and strings (list_1) is converted to a JSON-formatted string (json_str) using json.dumps().
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
The old version of JSON specified by the obsolete RFC 4627 required that the top-level value of a JSON text must be either a JSON object or array (Python dict or list), and could not be a JSON null, boolean, number, or string value.
🌐
Quora
quora.com › How-do-I-convert-a-list-to-JSON-in-Python
How to convert a list to JSON in Python - Quora
Answer (1 of 10): This is pretty basic. There is a inbuilt package which python provides called json. Simply import it then make a simple list and then write json.dumps(list). I think it will do the job. Another way to do : but its beneficial for large no. Of datas. You can convert the list to...
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › how to convert nested list into json?
r/learnpython on Reddit: How to convert nested list into JSON?
June 23, 2018 -

I know that, list can be converted into JSON by using json.dumps(mylist).

But how can I convert something like this into JSON ?

[["abc", "bcd", "cde"] , ["pgr", "xyz"]]

🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - Python and JSON have different data types, with Python offering a broader range of data types than JSON. While Python is capable of storing intricate data structures such as sets and dictionaries, JSON is limited to handling strings, numbers, booleans, arrays, and objects.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-json-to-list
Python Json To List - GeeksforGeeks
April 18, 2026 - JSON (JavaScript Object Notation) is a lightweight data-interchange format widely used in web development and data exchange. In Python, converting JSON to a list is a common task.
🌐
W3Schools
w3schools.com › PYTHON › python_json.asp
Python JSON
Python has a built-in package called json, which can be used to work with JSON data.
🌐
Reddit
reddit.com › r/learnpython › extremely confused with parsing a json array
r/learnpython on Reddit: Extremely confused with parsing a JSON array
April 14, 2017 -

Hi everyone. I'm really, really confused about parsing a JSON array.

For my script, I'll need to use a reverse geocoder, and I've decided to use Google's. I'm requesting a JSON, and it's returning this: https://developers.google.com/maps/documentation/geocoding/intro#reverse-example.

What I can't seem to figure out is the proper way of parsing it. I'm trying to extract the long_name in a few different types (for this example, let's say route, neighborhood, and administrative_area_level_2), and pass each long name for each type as their own string.

I'm completely lost on how to go about parsing this. I've tried json.loads, and doing a bunch of other things that fail in a "list indices must be integer", or unexpected results.

Right now, this is the nieve code I'm using to at least print long_name (about 30 times):

reverse_json = json.load(reader(reverseJSON))
# Excuse the debugging
print(reverse_json) 

for data in reverse_json['results']:
    address = data['address_components']
    for data in address:
        address = data['long_name']
        print(address)

And if I add on this to the final for loop:

if data['types'] == "['route']":
    address = data['long_name']
    print(address)

I get nothing.

json.loads doesn't help, either. It just results in

TypeError: the JSON object must be str, bytes or bytearray, not 'StreamReader'

So, I'm stuck with trying to parse a JSON array, and to have "long_name" become a certain variable if a certain type occurs. It's confusing to me, hopefully it isn't to you.

A simple explanation and help would be appreciated.

🌐
Python.org
discuss.python.org › python help
Unable to append data to Json array object with desired output - Python Help - Discussions on Python.org
January 18, 2023 - I’m tried getting help for same issue on stack-overflow but got no help or replies. I’m re-posting here with the hope that someone can please guide me as I’m unable to push the code to repository due to delay. My code import json import re from http.client import responses import vt import requests with open('/home/asad/Downloads/ssh-log-parser/ok.txt', 'r') as file: file = file.read() pattern = re.compile(r'\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}') ips = pattern.findall(file) unique_ips = lis...
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
December 3, 2024 - To access data within a JSON array, you can use array indexing, while to access data within an object, you can use key-value pairs.
🌐
TestMu AI Community
community.testmuai.com › ask a question
How can I convert a JSON array to a Python list? - Ask a Question - TestMu AI (formerly LambdaTest) Community
January 9, 2025 - I have the following JSON array: import json array = '{"fruits": ["apple", "banana", "orange"]}' data = json.loads(array) In this case, I want to convert all the values in the ‘fruits’ string to a Python list. What is the correct way of doing this using Python JSON to list?
🌐
Medium
medium.com › @datajournal › how-to-parse-json-data-with-python-99069a405e2b
How to Parse JSON Data With Python (EASY) | Medium
May 29, 2024 - However, JSON is not the same as a Python dictionary. When JSON data is loaded into Python, it is converted into a Python object, typically a dictionary or list. This allows for manipulation using standard Python methods. To save data back to JSON format, the `json.dumps()` function is used.
🌐
w3resource
w3resource.com › python-exercises › numpy › read-numeric-data-from-a-json-file-into-a-numpy-array.php
Read numeric data from a JSON file into a NumPy array
September 1, 2025 - Import NumPy and JSON Libraries: Import the NumPy and JSON libraries to handle arrays and JSON data. Define JSON File Path: Specify the path to the JSON file containing the numeric data.
🌐
Python Forum
python-forum.io › thread-35245.html
Write a dictionary with arrays as values into JSON format
Hi I'm working with dictionaries where values are (numpy) arrays, and I'm trying to figure out how to export these dictionaries in an JSON format, and how to read it afterward. I'm not familiar with JSON specifications and that's why I'm facing som...
🌐
Medium
medium.com › @AlexanderObregon › how-to-work-with-json-in-python-aef62d28eac4
How to Work with JSON in Python | Medium
November 2, 2024 - JSON data is represented as text formatted in key-value pairs, similar to a Python dictionary · It supports primitive data types like strings, numbers, booleans, lists (arrays), and nested objects (dictionaries).
🌐
Quora
quora.com › How-do-you-parse-a-JSON-list-in-Python
How to parse a JSON list in Python - Quora
Answer (1 of 3): Before you can start working with JSON in Python, you'll need some JSON to work with. There are a few things that you'll need to set up first. First, create a Python file that will hold your code for these exercises. Inside the file, import the JSON module. [code]import json [/c...
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - A key is a string you must wrap in double quotes ("). Unlike Python, JSON strings don’t support single quotes ('). The values in a JSON document are limited to the following data types: Just like in dictionaries and lists, you’re able to nest data in JSON objects and arrays.