• 19-06-2024, 14:31:46
    #1
    Selamlar;
    Elimde aşağıdaki gibi bir kod bulunuyor ve benim bu kod üzerinde bir düzenleme yapmam gerekiyor düzenleme temel olarak şu şekilde koddaki Localized kısımlarının altına "Price": 100 gibi bir kısım eklemem gerekiyor kod baya büyük ve uzun bir kod bunun için kullanabileceğim bir sistem var mı? ChatGPT denedim fakat o da harf sınırına takılıyor sorun çıkıyor.

  • 19-06-2024, 14:37:06
    #2
    import json
    
    # Function to add "Price" to each entry in the JSON data
    def add_price_to_json(json_data, price=100):
        for category in json_data.values():
            for item in category.values():
                item["Price"] = price
        return json_data
    
    # Read JSON data from a file
    with open('input.json', 'r') as file:
        data = json.load(file)
    
    # Modify the JSON data
    modified_data = add_price_to_json(data)
    
    # Write the modified JSON data back to a file
    with open('output.json', 'w') as file:
        json.dump(modified_data, file, indent=4)
    
    print("Price added to each entry successfully.")
    input.json kısmına dosyanın ismini ekleyin. ardından çalıştırın