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)

One-based column number where the parser encountered an error, counted in Unicode codepoints. Is nil when raised by JSON::ResumableParser.



143
144
145
# File 'lib/json/common.rb', line 143

def column
  @column
end

#line ⇒ Object (readonly)

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



139
140
141
# File 'lib/json/common.rb', line 139

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


153
154
155
156
157
158
159
160
161
# File 'lib/json/common.rb', line 153

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