0

Link to the .json file -> This is the link to the .json file.

I am making a Python based project and what I am trying to do here is to make use of a .json file. However when I tried to import it to use it with the GUI I got the following error.

Thank you in advance. Traceback (most recent call last):

  File "<ipython-input-1-31816de2c4db>", line 1, in <module>
    runfile('C:/Users/Akshita/pyex/Webmap/Gui.py', wdir='C:/Users/Akshita/pyex/Webmap')

 File "C:\Users\Akshita\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
   execfile(filename, namespace)

 File "C:\Users\Akshita\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

 File "C:/Users/Akshita/pyex/Webmap/Gui.py", line 12, in <module>
   data=json.load(open(r"C:\Users\Akshita\pyex\Webmap\world.json"))

 File "C:\Users\Akshita\Anaconda3\lib\json\__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)

  File "C:\Users\Akshita\Anaconda3\lib\json\__init__.py", line 354, in loads
   return _default_decoder.decode(s)

 File "C:\Users\Akshita\Anaconda3\lib\json\decoder.py", line 339, in decode
  obj, end = self.raw_decode(s, idx=_w(s, 0).end())

 File "C:\Users\Akshita\Anaconda3\lib\json\decoder.py", line 357, in raw_decode
  raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting value


# -*- coding: utf-8 -*-
"""
Created on Mon May 21 10:15:01 2018

@author: Akshita
"""

from tkinter import *
import json
import difflib
from difflib import get_close_matches
data=json.load(open(r"C:\Users\Akshita\pyex\Webmap\world.json"))
window=Tk()
window.title("Webmap")
l1=Label(window,text="Name_of_place")
l1.grid(row=0,column=0)
val=StringVar()
e=Entry(window,textvariable=val)
e.grid(row=0,column=1)
be=Button(window,text="Enter",command=entry)
be.grid(row=0,column=2)
def entry():

    w= e_val.get()

    w=w.title()

    if w in data:
     t.insert("Data matched")
    elif len(get_close_matches(w,data.keys(),cutoff=0.8))>0:
        t.insert("Did you mean %s instead?" %get_close_matches(w,data.keys())[0])  

t=Text(window,height=3,width=20)
t.grid(row=1,column=1)
by=Button(window,text="Yes",command=yeah)
by.grid(row=2,column=1)
def yeah():
    t.insert("Processing")

bn=Button(window,text="No",command=nah)
bn.grid(row=2,column=2)

def nah():
    t.insert("No such Data")

window.mainloop()
6
  • I have posted the complete error. :) Commented May 22, 2018 at 14:59
  • I have posted the complete error. :) Commented May 22, 2018 at 14:59
  • show your .json file Commented May 22, 2018 at 15:01
  • your JSON is invalid Commented May 22, 2018 at 15:10
  • But I have used this file in my other projects. Can you please tell me whether my code is correct? Also I have used the same .json file in other project and it worked. Thank you in advance. Commented May 22, 2018 at 15:15

1 Answer 1

0

Looks like your JSON file is invalid - the sequence of brackets at the end is incorrect.

The end should look like this:

... <previous data> ... ,[2.96361,36.802216]]]}}]}

You can use online or IDE JSON checkers to validate your file.


update

Got your full json file.

It turns out that it has UTF-8 BOM header. Try to load() it this way:

import json
import codecs

data = json.load(codecs.open('tst.json', 'r', 'utf-8-sig'))
print(data)

Related SO post: https://stackoverflow.com/a/13156715/2315573

Sign up to request clarification or add additional context in comments.

4 Comments

The example I gave was just an instance of the .json file. The file ends with the brackets in the same sequence you specified.
Error JSONDecodeError: Expecting value means that the JSON is invalid and parser cannot parse it. Can you give us an exact json file, not an example?
I am new to stackoverflow abd I don't know how to attach a file. Can you please help me?
if it's big enough, you may use a file hosting and paste a link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.