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
🌐
Stack Overflow
stackoverflow.com › questions › 40401035 › using-python-how-can-i-convert-json-to-array-list
Using python how can i convert json to array list - Stack Overflow
November 3, 2016 - Copyimport json with open("input.json") as json_file: data=json.load(json_file) for key, value in data.items(): print("json key: ", key) print("json value: ", str(value))
🌐
Tech With Tech
techwithtech.com › home › converting list to json array in python: how to?
Converting List to JSON Array in Python: How To? - Tech With Tech
October 27, 2022 - In case you want to load an object from JSON into a list, you have to use the loads method. By the way, converting an object (a list or a Python dictionary, for example) into a JSON string is called serialization, don’t be alarmed when you come across this word.
🌐
CodeSpeedy
codespeedy.com › home › convert json to list in python
Convert JSON to list in Python - CodeSpeedy
July 9, 2019 - Converting JSON to list in Python is easier than ever thought. We just have to use the loads() function. Check this tutorial out on how to convert them.
Find elsewhere
🌐
Towards Data Science
towardsdatascience.com › home › programming › how to perform json conversion, serialization, and comparison in python
How to Perform JSON Conversion, Serialization, and Comparison in Python | Towards Data Science
July 29, 2022 - In Python, the json library can be used for this type of conversion. We use the loads function to convert a JSON string into an object or an array, and use the dumps function to perform the opposite conversion.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-json-to-list
Python Json To List - GeeksforGeeks
April 18, 2026 - In this example, the below code utilizes the json.loads() method to convert a JSON-formatted string [1,2,3,4] into a Python list named arr. ... import json string = "[1,2,3,4]" arr = json.loads(string) print(type(string)) print(arr[0]) ...
Top answer
1 of 2
3
def replace_empty_dict_with(d, value):
    for k, v in d.iteritems():
        if len(v) == 0:
            d[k] = value
        else:
            replace_empty_dict_with(v, value)

d = {}
w = {}
for node, pid, _ in main_array:
    if pid == -1:
        w[node] = d[node] = {}
    else:
        parent = main_array[pid][0]
        w[node] = w[parent][node] = {}

replace_empty_dict_with(d, -1)
import pprint
pprint.pprint(d)

output:

{'some_string0': {'some_string3': -1,
                  'some_string4': -1,
                  'some_string5': {'some_string9': {'some_string11': -1}}},
 'some_string1': {'some_string6': -1, 'some_string7': {'some_string10': -1}},
 'some_string2': {'some_string8': -1}}
2 of 2
0

I understood the task a bit differently. I thought some_random_int was supposed to become the value in the final dictionary (not necessarily -1).

 main_json = {}
 id_to_dict_reference = {
      -1: main_json
 }
 id_to_container = {}
 id_to_key_name = {}

 for id, (var_some_string, parent_id, some_random_int) in enumerate(main_array):
      id_to_key_name[id] = var_some_string
      dict_reference = id_to_dict_reference[parent_id]

      if dict_reference is None:
           parent_container = id_to_container[parent_id]
           key_name = id_to_key_name[parent_id]
           if not isinstance(parent_container[key_name], dict):
                parent_container[key_name] = {}
           parent_container[key_name][var_some_string] = some_random_int
           id_to_dict_reference[id] = None
           id_to_container[id] = parent_container[key_name]
           id_to_dict_reference[parent_id] = parent_container[key_name]
      else:
           dict_reference[var_some_string] = some_random_int
           id_to_container[id] = dict_reference
           id_to_dict_reference[id] = None

 print main_json

output:

 {'some_string0': {'some_string3': -1,
                   'some_string4': -1,
                   'some_string5': {'some_string9': {'some_string11': -1}}},
  'some_string1': {'some_string6': -1, 'some_string7': {'some_string10': -1}},
  'some_string2': {'some_string8': -1}}
🌐
Awkward-array
awkward-array.org › doc › main › user-guide › how-to-convert-json.html
How to convert to/from JSON — Awkward Array 2.10.0 documentation
All of the rules that apply for Python objects in ak.from_iter() and ak.to_list() apply to ak.from_json() and ak.to_json(), replacing builtin Python types for JSON types. (One exception: JSON has no equivalent of a Python tuple.) Since Awkward Array internally uses RapidJSON to simultaneously parse and convert the JSON string, ak.from_json() and ak.to_json() should always be faster and use less memory than ak.from_iter() and ak.to_list().
🌐
W3Schools
w3schools.com › python › gloss_python_convert_into_JSON.asp
Python Convert From Python to JSON
When you convert from Python to JSON, Python objects are converted into the JSON (JavaScript) equivalent:
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
JSON is text, written with JavaScript object notation. Share Link Copied · Python has a built-in package called json, which can be used to work with JSON data. Import the json module: import json · If you have a JSON string, you can parse it by using the json.loads() method. The result will be a Python dictionary. Convert from JSON to Python: import json # some JSON: x = '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x) # the result is a Python dictionary: print(y["age"]) Try it Yourself » ·