AcidzDesigns
AcidzDesigns

Reputation: 1

Assistance needed with JSON

I'm creating a JSON file to hold information for commands.

The JSON file holds the trigger and repsonse for the commands, I have one in the file, but I want to add more, but when I do I get an error

{

  "trigger": "twitter",
  "repsonse": "https://www.twitter.com/Fhaelin"
}

{
  "trigger": "test",
  "repsonse": "This is a test command"
}

I get thrown errors and i dont know why

Here's the code I'm using to read it:

bot.on("message", function(message) {
  var input = message.content.toLowerCase();

  if (input === prefix + Commands.trigger)
  {
    bot.sendMessage(message, message.author + " : " + Commands.repsonse)
  }
})

Whole code http://hastebin.com/punabobisu.coffee

Upvotes: 0

Views: 31

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074295

You get errors because that's an invalid JSON document. There can only be one top-level value in a JSON document.

To have a list of objects, put them in an array: [..., ...]:

[
  {
    "trigger": "twitter",
    "response": "https://www.twitter.com/Fhaelin"
  },
  {
    "trigger": "test",
    "response": "This is a test command"
  }
]

Side note: You have a consistent misspelling in your question: It's "response", not "repsonse". Only mentioning it because it'll come back to bite you at some stage if you actually put it in your code.

Upvotes: 1

Related Questions