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 ?
#6
You don't show content of data.json.
Here is my test with a random validated json file.
data.json before:
{
    "devDependencies": {
        "eslint": "^6.8.0",
        "eslint-config-prettier": "^6.10.1",
        "prettier": "^2.0.2"
    },
    "scripts": {
        "eslint": "eslint . --fix",
        "eslint:check": "eslint .",
        "lint": "npm run prettier && npm run eslint"
    },
    "dependencies": {
        "@jsxtools/resize-observer": "^1.0.4"
    }
}
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)
data.json after:
Output:
{ "devDependencies": { "eslint": "^6.8.0", "eslint-config-prettier": "^6.10.1", "prettier": "^2.0.2" }, "scripts": { "eslint": "eslint . --fix", "eslint:check": "eslint .", "lint": "npm run prettier && npm run eslint", "emp_name": "Nikhil", "email": "[email protected]", "job_profile": "Full Time" }, "dependencies": { "@jsxtools/resize-observer": "^1.0.4" } }
Reply


Messages In This Thread
RE: How can i fix json.decoder.JSONDecodeError ? - by snippsat - Oct-30-2021, 04:33 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