0

In this file, I have created a JSON file.

This is my JSON.config { {
  "params":
  {
    "upload_location":"E:\\Ineuron Internship\\Automated ML\\AutoML\\uploads"


  },
}

In this file, I have written code for loading the file for JSON.

import json
from flask import request, Flask, render_template
import os
from werkzeug.utils import secure_filename
os.putenv('LANG', 'en_US.UTF-8')




os.putenv('LC_ALL', 'en_US.UTF-8')

with open('config.json','r')as E:
     params = json.load(E)



app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = params['upload_location']



@app.route("/", methods=['GET', 'POST'])
def home():
    return render_template('index.html')

@app.route("/uploader",methods = ['GET','POST'])
def uploader():
    if (request.method == 'POST'):
        f = request.files['file1']
        f.save(os.path.join(app.config['UPLOAD_FOLDER'],secure_filename(f.filename)))
        return "uploaded successfully"


if __name__ == "__main__":
    app.run(debug=True)

I get this error when I load it: JSON. decoder.JSONDecodeError: Expecting value:

or sometimes when I add something: JSON. decoder.JSONDecodeError: Expecting property name enclosed in double-quotes:

This is My ERROR:
    C:\Users\HP\anaconda3\envs\AutoML\python.exe "E:/Ineuron Internship/Automated 
    ML/AutoML/MAIN1.py"
    Traceback (most recent call last):
      File "E:/Ineuron Internship/Automated ML/AutoML/MAIN1.py", line 9, in <module>
        params = json.load(E)
      File "C:\Users\HP\anaconda3\envs\AutoML\lib\json\__init__.py", line 299, in load
        parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
      File "C:\Users\HP\anaconda3\envs\AutoML\lib\json\__init__.py", line 354, in loads
        return _default_decoder.decode(s)
      File "C:\Users\HP\anaconda3\envs\AutoML\lib\json\decoder.py", line 339, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "C:\Users\HP\anaconda3\envs\AutoML\lib\json\decoder.py", line 355, in raw_decode
        obj, end = self.scan_once(s, idx)
    json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 8 
    column 1 (char 103)
Omkar Kharkar
  • 11
  • 1
  • 4

1 Answers1

3

The problem isn't with your code, but is with your JSON file as far as I know:

This is my JSON.config { {
  "params":
  {
    "upload_location":"E:\\Ineuron Internship\\Automated ML\\AutoML\\uploads"


  }, # The extra comma here means another key is meant to be present
}

To fix this, just remove the comma:

This is my JSON.config { {
  "params":
  {
    "upload_location":"E:\\Ineuron Internship\\Automated ML\\AutoML\\uploads"


  }
}
Rushil Gupta
  • 182
  • 4