Exception: JSON::ParserError

Inherits:
JSONError show all
Defined in:
lib/json/common.rb

Overview

This exception is raised if a parser error occurs.

Direct Known Subclasses

NestingError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#column ⇒ Object (readonly)

Column number where the parser encountered an error. Is nil when raised by JSON::ResumableParser.



151
152
153
# File 'lib/json/common.rb', line 151

def column
  @column
end

#line ⇒ Object (readonly)

Line number where the parser encountered an error. Is nil when raised by JSON::ResumableParser.



147
148
149
# File 'lib/json/common.rb', line 147

def line
  @line
end

Instance Method Details

#json_path ⇒ Object

Returns a best effort JSONPath string representing where in the document the parser encountered an error:

begin
JSON.parse('{"articles": [ { "title": invalid } ]}')
rescue JSON::ParserError => error
error.json_path # => "$.articles[0].title"
end


161
162
163
164
165
166
167
168
169
# File 'lib/json/common.rb', line 161

def json_path
  return @json_path if String === @json_path

  if Array === @json_path
    path = build_json_path(@json_path)
    @json_path = path unless frozen?
    return path
  end
end