Python Forum
Serializing Python data Correctly (JSON)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serializing Python data Correctly (JSON)
#1
Hi, I want to store the users I created in the file named "asdsad". The first information is being processed correctly, but the second information is overwritten by the first information. I don't want this. I want the "json" data to be written at the bottom. Where am I making a mistake?

AccInformation.json
{
 "67368262694": {
  "T.C": "32424324",
  "Adı": "Super",
  "Soyadı": "UZUN",
  "E-Posta": "[email protected]",
  "Kullanıcı Adı": "jgkSUperstar",
  "Şifresi": "123456",
  "Kullanıcı Anahtarı": "KDW6-T7L1-EPMB-H92Y-AS0O-VNZ4",
  "Kayıt Tarihi": "04/Kasim/2021 - Saat : 15:14"
 }
}
The next data needs to come under the above data. Example :
{
"67368262694": {
    "T.C": "32424324",
    "Adı": "Super",
    "Soyadı": "UZUN",
    "E-Posta": "[email protected]",
    "Kullanıcı Adı": "jgkSUperstar",
    "Şifresi": "123456",
    "Kullanıcı Anahtarı": "KDW6-T7L1-EPMB-H92Y-AS0O-VNZ4",
    "Kayıt Tarihi": "04/Kasim/2021 - Saat : 15:14"
},
 "12457262694": {
    "T.C": "75424323",
    "Adı": "aaaaaa",
    "Soyadı": "KISA",
    "E-Posta": "[email protected]",
    "Kullanıcı Adı": "Harveyspecter",
    "Şifresi": "123456",
    "Kullanıcı Anahtarı": "CDW6-T7L1-EPMB-H92Y-AS0O-VNZ4",
    "Kayıt Tarihi": "04/Kasim/2021 - Saat : 15:14"
   }
}
I have changed my codes many times, but I have not been able to overcome this problem..

Mycode :
import sqlite3 as sqlite
import Generator
import datetime
import locale
import GeneralSecure
import os
import json
import time

locale.setlocale(locale.LC_ALL, '')
# Account Management
class Account:

    def __init__(self, user_id, TCKN, firstName, lastName, 
                 email, username, password, accountKEY, register_date):
        #, Get & Set
        self.user_id = user_id
        self.TCKN = TCKN 
        self.firstName = firstName
        self.lastName = lastName
        self.email = email
        self.username = username
        self.password = password
        self.accountKEY = accountKEY
        self.register_date = register_date

class AccountManagement:
    def __init__(self):
        self.PendingUsers = {} 


    def CreateAccount(self, user_id, TCKN, firstName, lastName, 
                      email, username, password, accountKEY, register_date, filename='AccInformation.json'):
        gay = datetime.datetime.now() # gay = gün / ay / yıl / saat
        register_date = datetime.datetime.strftime(gay, '%d/%B/%Y - Saat : %H:%M')
        igenerator = Generator.Production()
        user_id = igenerator.id_generator()
        accountKEY = igenerator.license_generator()
        
        self.PendingUsers.update({
            user_id:{
                "T.C": TCKN,
                "Adı": firstName,
                "Soyadı": lastName,
                "E-Posta": email,
                "Kullanıcı Adı": username,
                "Şifresi": password,
                "Kullanıcı Anahtarı": accountKEY,
                "Kayıt Tarihi": register_date
            }
        })
        self.WriteFile(self.PendingUsers)
        
    def WriteFile(self, user, filename='AccInformation.json'):
        with open(filename, "r+", encoding='utf-8') as json_write:
            json.dump(user, json_write, indent=1, ensure_ascii=False)

register = AccountManagement()
register.CreateAccount("128", "32424324", "eeeee", "UZUN", "[email protected]", "test", "123456", "1", "1")
Reply


Messages In This Thread
Serializing Python data Correctly (JSON) - by JgKSuperstar - Nov-04-2021, 12:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why can I not see the code correctly in Python IDLE.? Trump 8 997 Apr-04-2024, 07:47 AM
Last Post: jonesphedra
  encrypt data in json file help jacksfrustration 1 530 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Correctly read a malformed CSV file data klllmmm 2 2,340 Jan-25-2023, 04:12 PM
Last Post: klllmmm
  Read nested data from JSON - Getting an error marlonbown 5 1,611 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 1,249 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Python Split json into separate json based on node value CzarR 1 6,125 Jul-08-2022, 07:55 PM
Last Post: Larz60+
  Convert nested sample json api data into csv in python shantanu97 3 3,157 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 2,151 May-09-2022, 02:49 AM
Last Post: snippsat
  json api data parsing elvis 0 1,007 Apr-21-2022, 11:59 PM
Last Post: elvis
  Capture json data JohnnyCoffee 0 1,297 Nov-18-2021, 03:19 PM
Last Post: JohnnyCoffee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020