All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | List of all members
nlohmann::detail::parse_error Class Reference

exception indicating a parse error More...

#include <json.hpp>

Inheritance diagram for nlohmann::detail::parse_error:
nlohmann::detail::exception

Static Public Member Functions

static parse_error create (int id_, const position_t &pos, const std::string &what_arg)
 create a parse error exception More...
 
static parse_error create (int id_, std::size_t byte_, const std::string &what_arg)
 

Public Attributes

const std::size_t byte
 byte index of the parse error More...
 
- Public Attributes inherited from nlohmann::detail::exception
const int id
 the id of the exception More...
 

Private Member Functions

 parse_error (int id_, std::size_t byte_, const char *what_arg)
 

Static Private Member Functions

static std::string position_string (const position_t &pos)
 

Additional Inherited Members

- Public Member Functions inherited from nlohmann::detail::exception
JSON_HEDLEY_RETURNS_NON_NULL
const char * 
what () const noexceptoverride
 returns the explanatory string More...
 
- Protected Member Functions inherited from nlohmann::detail::exception
 exception (int id_, const char *what_arg)
 
- Static Protected Member Functions inherited from nlohmann::detail::exception
static std::string name (const std::string &ename, int id_)
 

Detailed Description

exception indicating a parse error

This exception is thrown by the library when a parse error occurs. Parse errors can occur during the deserialization of JSON text, CBOR, MessagePack, as well as when using JSON Patch.

Member byte holds the byte index of the last read character in the input file.

Exceptions have ids 1xx.

name / id example message description
json.exception.parse_error.101 parse error at 2: unexpected end of input; expected string literal This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member byte indicates the error position.
json.exception.parse_error.102 parse error at 14: missing or wrong low surrogate JSON uses the \uxxxx format to describe Unicode characters. Code points above above 0xFFFF are split into two \uxxxx entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point.
json.exception.parse_error.103 parse error: code points above 0x10FFFF are invalid Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid.
json.exception.parse_error.104 parse error: JSON patch must be an array of objects RFC 6902 requires a JSON Patch document to be a JSON document that represents an array of objects.
json.exception.parse_error.105 parse error: operation must have string member 'op' An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors.
json.exception.parse_error.106 parse error: array index '01' must not begin with '0' An array index in a JSON Pointer (RFC 6901) may be 0 or any number without a leading 0.
json.exception.parse_error.107 parse error: JSON pointer must be empty or begin with '/' - was: 'foo' A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a / character.
json.exception.parse_error.108 parse error: escape character '~' must be followed with '0' or '1' In a JSON Pointer, only ~0 and ~1 are valid escape sequences.
json.exception.parse_error.109 parse error: array index 'one' is not a number A JSON Pointer array index must be a number.
json.exception.parse_error.110 parse error at 1: cannot read 2 bytes from vector When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read.
json.exception.parse_error.112 parse error at 1: error reading CBOR; last byte: 0xF8 Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read.
json.exception.parse_error.113 parse error at 2: expected a CBOR string; last byte: 0x98 While parsing a map key, a value that is not a string has been read.
json.exception.parse_error.114 parse error: Unsupported BSON record type 0x0F The parsing of the corresponding BSON record type is not implemented (yet).
Note
For an input with n bytes, 1 is the index of the first character and n+1 is the index of the terminating null byte or the end of file. This also holds true when reading a byte vector (CBOR or MessagePack).

{The following code shows how a parse_error exception can be caught.,parse_error}

See Also
- exception for the base class of the library exceptions
- invalid_iterator for exceptions indicating errors with iterators
- type_error for exceptions indicating executing a member function with a wrong type
- out_of_range for exceptions indicating access out of the defined range
- other_error for exceptions indicating other library errors
Since
version 3.0.0

Definition at line 1935 of file json.hpp.

Constructor & Destructor Documentation

nlohmann::detail::parse_error::parse_error ( int  id_,
std::size_t  byte_,
const char *  what_arg 
)
inlineprivate

Definition at line 1974 of file json.hpp.

1975  : exception(id_, what_arg), byte(byte_) {}
const std::size_t byte
byte index of the parse error
Definition: json.hpp:1971
exception(int id_, const char *what_arg)
Definition: json.hpp:1879

Member Function Documentation

static parse_error nlohmann::detail::parse_error::create ( int  id_,
const position_t pos,
const std::string what_arg 
)
inlinestatic

create a parse error exception

Parameters
[in]id_the id of the exception
[in]posthe position where the error occurred (or with chars_read_total=0 if the position cannot be determined)
[in]what_argthe explanatory string
Returns
parse_error object

Definition at line 1947 of file json.hpp.

1948  {
1949  std::string w = exception::name("parse_error", id_) + "parse error" +
1950  position_string(pos) + ": " + what_arg;
1951  return parse_error(id_, pos.chars_read_total, w.c_str());
1952  }
parse_error(int id_, std::size_t byte_, const char *what_arg)
Definition: json.hpp:1974
static std::string position_string(const position_t &pos)
Definition: json.hpp:1977
static std::string name(const std::string &ename, int id_)
Definition: json.hpp:1881
static parse_error nlohmann::detail::parse_error::create ( int  id_,
std::size_t  byte_,
const std::string what_arg 
)
inlinestatic

Definition at line 1954 of file json.hpp.

1955  {
1956  std::string w = exception::name("parse_error", id_) + "parse error" +
1957  (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
1958  ": " + what_arg;
1959  return parse_error(id_, byte_, w.c_str());
1960  }
parse_error(int id_, std::size_t byte_, const char *what_arg)
Definition: json.hpp:1974
static std::string name(const std::string &ename, int id_)
Definition: json.hpp:1881
std::string to_string(WindowPattern const &pattern)
static std::string nlohmann::detail::parse_error::position_string ( const position_t pos)
inlinestaticprivate

Definition at line 1977 of file json.hpp.

1978  {
1979  return " at line " + std::to_string(pos.lines_read + 1) +
1980  ", column " + std::to_string(pos.chars_read_current_line);
1981  }
std::string to_string(WindowPattern const &pattern)

Member Data Documentation

const std::size_t nlohmann::detail::parse_error::byte

byte index of the parse error

The byte index of the last read character in the input file.

Note
For an input with n bytes, 1 is the index of the first character and n+1 is the index of the terminating null byte or the end of file. This also holds true when reading a byte vector (CBOR or MessagePack).

Definition at line 1971 of file json.hpp.


The documentation for this class was generated from the following file: