N
N
nnikolyaa2020-06-25 14:55:07
Python
nnikolyaa, 2020-06-25 14:55:07

Json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 58) what is causing the error?

What is the error and how to solve it?
Mistake:

Traceback (most recent call last):
  File "/home/nnikolyaa/Vk_bot.py", line 341, in <module>
    main()
  File "/home/nnikolyaa/Vk_bot.py", line 159, in main
    data = json.load(f)
  File "/usr/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 58)

The code:
elif str(pextxt) == '/pex ':
                    with open('config.json') as f:
                        data = json.load(f)
                    data[peid] = fal
                    with open('config.json', 'w') as f:
                        json.dump(data, pextxt2=fal, indent=4)
                    vk.messages.send(
                        peer_id=event.object.peer_id,
                        random_id=get_random_id(),
                        message=("Теперь в беседе "+str(peid)+' значение '+str(pextxt2)+' заменено на '+str(fal))
                    )

config.json:
{"2000000003": {"amv": true, "amvl": true, "whoa": true}}
{"2000000004": {"amv": true, "amvl": true, "whoa": true}}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2020-06-25
@nnikolyaa

Bring config.json to this form - and there will be happiness (but this is not accurate):

[
{"2000000003": {"amv": true, "amvl": true, "whoa": true}},
{"2000000004": {"amv": true, "amvl": true, "whoa": true}}
]

S
Sergey Gornostaev, 2020-06-25
@sergey-gornostaev

Due to the fact that your file content does not match the JSON format.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question