jsonparser icon indicating copy to clipboard operation
jsonparser copied to clipboard

Parser can't handle single quotes (instead of double quotes)

Open jeremy-tafi opened this issue 7 years ago • 3 comments

data := "{'value':'data'}"
str, err := jsonparser.GetString([]byte(data), "value")
if err != nil {
	fmt.Print(err)
} else {
  fmt.Print(str)
}

This example fails to find the key "value" because it is surrounded by single quotes instead of double quotes. Even though "technically", they should be double quotes, it'd be nice if the parser handled single quotes interchangeably.

jeremy-tafi avatar Mar 29 '19 03:03 jeremy-tafi

That's not valid JSON, keys and sting values must be surrounded by double quotes: https://www.json.org/

nicpottier avatar Mar 29 '19 12:03 nicpottier

That's true, but in programming languages, especially when trying to encapsulate JSON or other strings, single quotes and double quotes are used interchangeably. It would be nice for the library to support it.

On Fri, Mar 29, 2019 at 8:58 AM Nic Pottier [email protected] wrote:

That's not valid JSON, keys and sting values must be surrounded by double quotes: https://www.json.org/

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/buger/jsonparser/issues/160#issuecomment-477988413, or mute the thread https://github.com/notifications/unsubscribe-auth/Asufth3QkamKlqb5IGdkcQXwG7GWiDXMks5vbg4KgaJpZM4cRjHY .

-- Jeremy Reed | Software Engineer | tafi.io http://www.tafi.io/

jeremy-tafi avatar Mar 29 '19 14:03 jeremy-tafi

That's true, but in programming languages, especially when trying to encapsulate JSON or other strings, single quotes and double quotes are used interchangeably. It would be nice for the library to support it.

Well, that’s just not a good practice.

remychantenay avatar May 19 '20 16:05 remychantenay