buger / jsonparser

One of the fastest alternative JSON parser for Go that does not require schema
MIT License
5.46k stars 435 forks source link

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

Open jeremy-tafi opened 5 years ago

jeremy-tafi commented 5 years ago
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.

nicpottier commented 5 years ago

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

jeremy-tafi commented 5 years ago

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 notifications@github.com 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/

remychantenay commented 4 years ago

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.