You need to maintain two lists for scores and titles and append all the data to those lists, instead of printing, and then zip those lists along with list comprehension to get the desired output as :

import json
scores, titles = [], []
for line in games_html.findAll('div', class_="product_score"):
    scores.append(line.getText(strip=True))

for line in games_html.findAll('a'):
    titles.append(line.getText(strip=True))

score_titles = [{"Title": t, "Score": s} for t, s in zip(titles, scores)]
print score_titles
# Printing in JSON format
print json.dumps(score_titles)
Answer from ZdaR on Stack Overflow
Discussions

How to create a json file from list in python? - Stack Overflow
I am tring to create a json file with my lists in my python code: I have arr_of_id_by_user = [1, 2, 3] arr_of_wallet_amount = [100,3400,200] I would like this to return in the json file like jsonf... More on stackoverflow.com
🌐 stackoverflow.com
How do I create json array of objects using python - Stack Overflow
I have a list of countries and their cities on one website. I take all names of countries and their capitals from this list, and want to put them in JSON file like this: [ { "country&quo... More on stackoverflow.com
🌐 stackoverflow.com
Python: Convert a list of python dictionaries to an array of JSON objects - Stack Overflow
I expected I could append a dictionary ... to a python list and it wouldn't matter that all of the dictionaries have the same key because they would be independent. Thanks for your help. ... You are adding the exact same dictionary to the list. You should create a new dictionary for each item in the list: ... Sign up to request clarification or add additional context in comments. ... can we do a reverse of this ? converting a string which is array of json objects to ... More on stackoverflow.com
🌐 stackoverflow.com
Create json array using list in python - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 2
15

... the JSON array at the end of your answer is incorrect, but to generate an array, just give a list to json.dumps in Python. Something like json_data_list = []; ... ; json_data_list.append(json_data); ... print(json.dumps(json_data_list)); ...

2 of 2
2

Your JSON file is incorrect. Normally you must have a structure as:

{
    "key1": [
        {
            "id": "blabla",
            "name": "Toto"
        },
        {
            "id": "blibli",
            "name": "Tata"
        }
    ],
    "key2": {
        "id": "value"
    },
    "key3": "value"
}

So I think you have to change your JSON array for example as following:

{
    [
        {
            "id": 0,
            "organizer": "Some Name",
            "eventStart": "09:30 AM",
            "eventEnd": "10:00 AM",
            "subject": "rental procedure",
            "attendees": "Some Name<br />Person 2<br />Person 3"
        },
        {
            "id": 1,
            "organizer": "Some Name",
            "eventStart": "09:30 AM",
            "eventEnd": "10:00 AM",
            "subject": "rental procedure",
            "attendees": "Some Name<br />Person 2<br />Person 3"
        },
        {
            "id": 2,
            "organizer": "Some Name",
            "eventStart": "09:30 AM",
            "eventEnd": "10:00 AM",
            "subject": "rental procedure",
            "attendees": "Some Name<br />Person 2<br />Person 3"
        }
    ]
}

You can decide also to have not a list of dictionary as I proposed above but to use the ID value as key for each dictionary; in that case you have:

{
    "id0":{       
            "organizer": "Some Name",
            "eventStart": "09:30 AM",
            "eventEnd": "10:00 AM",
            "subject": "rental procedure",
            "attendees": "Some Name<br />Person 2<br />Person 3"
    },
    "id1":{       
            "organizer": "Some Name",
            "eventStart": "09:30 AM",
            "eventEnd": "10:00 AM",
            "subject": "rental procedure",
            "attendees": "Some Name<br />Person 2<br />Person 3"
    },
    "id2":{       
            "organizer": "Some Name",
            "eventStart": "09:30 AM",
            "eventEnd": "10:00 AM",
            "subject": "rental procedure",
            "attendees": "Some Name<br />Person 2<br />Person 3"
    }
}
🌐
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 - Another way is to use the zip function. It takes two lists as input and returns a sequence of tuples with the values from those lists. The first element of a zip object is the first value of the first list and the first value of the second list.
🌐
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...
🌐
Python Examples
pythonexamples.org › python-create-json
Python Create JSON
Learn how to create JSON strings from Python dictionaries, lists, and tuples. This tutorial covers JSON creation techniques using the json.dumps() function with practical examples.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 70578104 › how-do-i-create-json-array-of-objects-using-python
How do I create json array of objects using python - Stack Overflow
Python obviously has no way to know that you are writing a list of objects when you are writing them one at a time ... so just don't. cells = soup.table('td') cities = [] for cell in cells[:-2]: cities.append({"country": str(cells[count].getText()), "city": str(cells[count].next_sibling.getText())}) json.dump(cities, cities_list)
🌐
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 Examples
pythonexamples.org › python-list-to-json
Python List to JSON
import json a_list = [{'a':1, 'b':2}, {'c':3, 'd':4}] json_string = json.dumps(a_list) print(json_string) ... In this example, we will take a Python List of Lists and convert it to JSON string.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... JSON is a syntax for storing and exchanging data.
🌐
Reddit
reddit.com › r/learnpython › create json objects dynamically with lists?
r/learnpython on Reddit: create JSON objects dynamically with lists?
April 24, 2024 -

hey there, i want to create a json file from 2 lists (label, data) where every item has different properties.

label[x] = ["Part Number", "name", "weight", ...] 
data[x] = ["33882", "screw", "23g", ...] 

label[y] = ["Part Number", "name", "color", ...] 
data[y]= ["33882", "screw", "red", ...] 

It should look something like this:

{ 
  "item x" : { 
    "Part Number": "33882", 
    "name": "screw", 
    "weight: "23g 
  }, 
  "item y: " { 
    "Part Number": "47342", 
    "name": "hammer", 
    "color: "red, 
    "label: "data 
  }, 
}

if have no idea how to achiev this since my python skills are pretty basic and i couldn't find any examples which helped me.

would somebody give me a hint or example please?

🌐
Kite
kite.com › python › answers › how-to-convert-a-list-to-a-json-array-in-python
Kite is saying farewell - Code Faster with Kite
November 20, 2022 - That’s not the outcome we were hoping for when we started, but we celebrate the courage and contributions from everyone who made the experiment happen. Thank you, and keep building. P.S. Most of our code has been open sourced on Github here. It includes our data-driven Python type inference engine, Python public-package analyzer, desktop software, editor integrations, Github crawler and analyzer, and much more.
🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - 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. Let’s look at some of the differences: To convert a Python list to JSON format, you can use the json.dumps() method from the ...
🌐
Stack Overflow
stackoverflow.com › questions › 38176182 › how-to-create-an-array-of-objects-in-json-using-python
How to create an array of objects in JSON, using python? - Stack Overflow
May 23, 2017 - As pointed out below my answer is incorrect because lists do not have names but you could try to combine it with this answer to set up something that aims at what you are trying to do ... names = [a.__name__ for a in arrays] objs = [] For arrs in zip(arrays): objs.append({"array_" + n: val for n, val in zip(names, arrs)})
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › convert python list to json examples
Convert Python List to JSON Examples - Spark By {Examples}
March 27, 2024 - How to convert a list to JSON in Python? You can use the json.dumps() method to convert a Python list to a JSON string. This function takes a list as an