I
I
Igor_Merg2021-01-05 21:59:09
Python
Igor_Merg, 2021-01-05 21:59:09

I am writing a database in json, but an error occurs?

Hi everyone, I've come across this problem:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "bot.py", line 179, in ls_chat
    data = json.load(file)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 9 column 2 (char 229)

I need to get data from a file
Piece of code:
with open('bd_zakaz.txt','r') as file: 
    data = json.load(file)

What should be in the database:
{
   "2205953": {
      "id": 463379321,
      "nick": "Igor_Pavlov",
      "mesto": "\u0422\u0422\u0423-\u041d",
      "kuda": "\u0410\u0432\u0442\u043e\u0441\u0430\u043b\u043e\u043d-\u041d",
      "nomer_zakaza": 2205953
   }
}{
   "2205953": {
      "id": 463379321,
      "nick": "Igor_Pavlov",
      "mesto": "\u0422\u0422\u0423-\u041d",
      "kuda": "\u0410\u0432\u0442\u043e\u0441\u0430\u043b\u043e\u043d-\u041d",
      "nomer_zakaza": 2205953
   },
   "4545777": {
      "id": 463379321,
      "nick": "Igor_Pavlov",
      "mesto": "1",
      "kuda": "1",
      "nomer_zakaza": 4545777
   }
}

The numbers at the beginning are the order number, as I understand json I don’t like it, please help me how to get around the error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-01-05
@Igor_Merg

}{

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question