json icon indicating copy to clipboard operation
json copied to clipboard

Better error message for "JSON::ParserError at"

Open sandipsubedi opened this issue 7 years ago • 0 comments

We have an application where user makes restful api calling using JSON data. Few times the JSON is invalid, either comma is missing or they don't have proper quotes. But the error message that will get looks like follows:

JSON::ParserError at /api/person/create
===============================================
> 765: unexpected token at '{    "firstname": "hello"  "lastname": "world" }'

json (2.1.0) lib/json/common.rb, line 156

The error message is coming from here:

https://github.com/flori/json/blob/master/lib/json/common.rb#L155

Is there a way to tell it's an Invalid JSON instead of throwing JSON::ParserError?

It seems like JSON::ParseError means it's invalid JSON. But not sure if this is always true?

sandipsubedi avatar Aug 24 '18 22:08 sandipsubedi