0

I'm trying to do an entry code a long project and I hit an error with my .json file trying to load my .py file. The code I have is the exact same and the only difference is that he's using pycharm and I'm using sublime. It says that my json file has no build system, but I have automatic selected. Not sure if that is the potential problem or not.

Error in question:

    json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes

Code in question:

    intents = json.loads(open('intents.json').read())

Json file in question:

{"intents": [
        {"tag": "greeting",
         "patterns": ["Hi", "How are you", "Is anyone there?", "Hello", "Good day", "Whats up", "Howdy", "Greetings"],
         "responses": ["Hello!", "Good to see you again!", "Hi there, how can I help?", "What can I do for you?"],
        },
        {"tag": "goodbye",
         "patterns": ["cya", "See you later", "Goodbye", "I am Leaving", "Have a Good day", "I'm out", "Peace", "bye", "cao", "see ya"],
         "responses": ["Sad to see you go :(", "Talk to you later", "Goodbye!", "Have a nice day"],
        },
        {"tag": "age",
         "patterns": ["how old", "how old is Nicolas", "what is your age", "how old are you", "age?"],
         "responses": ["I am 24 years old!", "24 years young!"],
        },
        {"tag": "name",
         "patterns": ["what is your name", "what should I call you", "whats your name?", "who are you", "Can you tell me your name"],
         "responses": ["You can call me Nic.", "I'm Nic!", "I'm Nicolas, or you can just call me Nic."],
        },
        {"tag": "shop",
         "patterns": ["Id like to buy something", "whats on the menu", "what do you serve here?" "what do you reccommend?", "could i get something to eat", "I'd like to place an order"],
         "responses": ["Hello! We sell Subs for $7!", "Subs are on the menu!"],
        },
        {"tag": "hours",
         "patterns": ["when are you guys open?", "what are your hours?", "hours of operation?", "What's your hours like?"],
         "responses": ["We are open 7am-7pm Monday-Friday!"],
        }
   ]
Nic Doar
  • 1
  • 2
  • 1
    Does this answer your question? [JSON ValueError: Expecting property name: line 1 column 2 (char 1)](https://stackoverflow.com/questions/25707558/json-valueerror-expecting-property-name-line-1-column-2-char-1) – Nick May 28 '22 at 00:38
  • I'm sorry to ask, but which answer were you referring to? – Nic Doar May 28 '22 at 01:04
  • The first answer talks about the "final comma issue", which is what is wrong with your JSON – Nick May 28 '22 at 01:05

1 Answers1

2

Strictly speaking, your JSON is not valid, because of the trailing commas in each object in the intents array e.g.:


{"tag": "greeting",
 "patterns": ["Hi", "How are you", "Is anyone there?", "Hello", "Good day", "Whats up", "Howdy", "Greetings"],
 "responses": ["Hello!", "Good to see you again!", 
               "Hi there, how can I help?", "What can I do for you?"
              ],
}
               ^^^^ illegal trailing comma here 

If you remove these commas, the JSON will load fine using json.loads

Note that jsonlint.com is a good place to validate your JSON.

Nick
  • 138,499
  • 22
  • 57
  • 95