Python Forum
How can i fix json.decoder.JSONDecodeError ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i fix json.decoder.JSONDecodeError ?
#5
(Oct-30-2021, 12:16 PM)snippsat Wrote:
file_data = json.load(file)
When you do this file_data it's a dictionary.
Then on line-11 can not use .append as that method is only for list.
For dictionary can use .update
Don't use try: except with return nothing,when test out stuff want to see all errors.
Quick test working.
import json
from pprint import pprint

def write_json(new_date, filename='data.json'):
    with open(filename, 'r+') as file:
        file_data = json.load(file)
        #print(file_data)

        file_data["scripts"].update(new_date)
        #pprint(file_data)
        file.seek(0)
        json.dump(file_data, file, indent=4)

if __name__ == '__main__':
    y = {
        "emp_name": "Nikhil",
        "email": "[email protected]",
        "job_profile": "Full Time",
    }
    write_json(y)


I'm getting the same mistake again. Could it be that when we turn it on to read mode, the "data.json" file is empty and gives it this error?

[Image: jdec33t.png]';" src="[Image: jdec33t.png]" alt="İmage" id="maximage" title="Click Photo To Enlarge">
Reply


Messages In This Thread
RE: How can i fix json.decoder.JSONDecodeError ? - by JgKSuperstar - Oct-30-2021, 03:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  JSONDecodeError: Expecting value mehtamonita 1 1,606 Mar-07-2022, 04:24 PM
Last Post: bowlofred
  Problems with JSONDecodeError arsouzaesilva 0 1,499 Sep-22-2021, 06:33 PM
Last Post: arsouzaesilva
  coding a decoder... Popkhorn 2 2,228 May-28-2020, 07:26 AM
Last Post: Popkhorn
  reset on inactivity (building a morse decoder) gerrit1985 7 3,729 Apr-17-2020, 10:22 AM
Last Post: deanhystad
  UTF-8 decoder reports bad byte that is not there Skaperen 0 2,376 Oct-11-2018, 04:46 AM
Last Post: Skaperen
  MP4 decoder jdewk 4 5,760 Jan-13-2018, 10:02 PM
Last Post: jdewk
  JSON Decoder issue Cronax3 2 9,879 Sep-13-2017, 09:23 AM
Last Post: Cronax3

Forum Jump:

User Panel Messages

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