0

First let me say that while I am a programmer, Ruby is very new to me. I'm trying to fix an application created by another developer, but I cannot find the issue. When the code is run, I get the error below:

JSON::ParserError: unexpected token at '{
  "account":"xxxxxxx",
  "role":"3",
  "email":"xxxx@xxxxxxxx.com",
  "password":'xxxxxxxxxxxx',
  "connect_host":"xxxxxxx.xxxxxxx.api.xxxxxxxx.com"
}
'

Account is numeric. Email is standard/no special characters. Password does have special characters, on of them being a double quote which is why it is wrapped in single quotes. Connect host is just an URL with alpha-numeric characters. I've Googled quite a bit but the results I've come up with dealt with people trying to escape certain characters. My hope is that another set of eyes can see what mine are missing.

John
  • 65
  • 2
  • 13

1 Answers1

2

Based on the JSON you've pasted in above the error is the usage of single quotes for the value of "password" which is 'xxxxxxxxxxxx'.

It needs to be in double quotes so change it to be:

"password":"xxxxxxxxxxxx",

If you control the code that sets the input go change that otherwise you will have to handle changing the single quote usage possibly through this answer (which is JS but demonstrates the concept), Parsing string as JSON with single quotes?

Matthew
  • 2,759
  • 18
  • 28
  • 1
    Thank you. I was just about to post that I found the problem (figures, 5 minutes after I post the question). The password was originally in double quotes, but it was changed when the programmer who wrote this left. The new one I created had a double quote in it, so I wrapped the whole thing in single quotes. Thought of some of the escaping issues I was reading about and put it back in double quotes and escaped the double quote in the password. Works fine now. – John Nov 12 '20 at 19:36