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 ?
#10
(Oct-30-2021, 10:18 PM)snippsat Wrote:
(Oct-30-2021, 10:12 PM)squad Wrote: If the json file is not empty, the yes code does not give an error
If start with empty file can not use json.load(file) on that file.
Make the the structure you want first with a dictionary,then json.dump to make it json file.
Example.
import json
from pprint import pprint

def write_json(new_date, filename='d.json'):
    json_make = {}
    with open(filename, 'r+') as file:
        json_make["emp_details"] = new_date
        file.seek(0)
        json.dump(json_make, file, indent=4)

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

I'm sorry for troubling you. Thank you very much for your patience and help my problem has been solved :) <3
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  JSONDecodeError: Expecting value mehtamonita 1 2,467 Mar-07-2022, 04:24 PM
Last Post: bowlofred
  Problems with JSONDecodeError arsouzaesilva 0 1,895 Sep-22-2021, 06:33 PM
Last Post: arsouzaesilva
  coding a decoder... Popkhorn 2 2,756 May-28-2020, 07:26 AM
Last Post: Popkhorn
  reset on inactivity (building a morse decoder) gerrit1985 7 5,021 Apr-17-2020, 10:22 AM
Last Post: deanhystad
  UTF-8 decoder reports bad byte that is not there Skaperen 0 2,912 Oct-11-2018, 04:46 AM
Last Post: Skaperen
  MP4 decoder jdewk 4 6,925 Jan-13-2018, 10:02 PM
Last Post: jdewk
  JSON Decoder issue Cronax3 2 10,613 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