JSON for Modern C++

These pages contain the API documentation of JSON for Modern C++, a C++11 header-only JSON class.


  • @link nlohmann::basic_json basic_json class @endlink
  • Functions
    • object inspection
      • @link nlohmann::basic_json::dump dump @endlink -- value serialization
      • @link nlohmann::basic_json::type type @endlink -- type of the value
      • @link nlohmann::basic_json::is_primitive is_primitive @endlink, @link nlohmann::basic_json::is_structured is_structured @endlink, @link nlohmann::basic_json::is_null is_null @endlink, @link nlohmann::basic_json::is_boolean is_boolean @endlink, @link nlohmann::basic_json::is_number is_number @endlink, @link nlohmann::basic_json::is_number_integer is_number_integer @endlink, @link nlohmann::basic_json::is_number_unsigned is_number_unsigned @endlink, @link nlohmann::basic_json::is_number_float is_number_float @endlink, @link nlohmann::basic_json::is_object is_object @endlink, @link nlohmann::basic_json::is_array is_array @endlink, @link nlohmann::basic_json::is_string is_string @endlink, @link nlohmann::basic_json::is_discarded is_discarded @endlink -- check for value type
      • @link nlohmann::basic_json::operator value_t() const operator value_t @endlink -- type of the value (implicit conversion)
    • value access
      • @link nlohmann::basic_json::get get @endlink -- get a value
      • @link nlohmann::basic_json::get_ptr get_ptr @endlink -- get a value pointer
      • @link nlohmann::basic_json::get_ref get_ref @endlink -- get a value reference
      • @link nlohmann::basic_json::operator ValueType() const operator ValueType @endlink -- get a value (implicit conversion)
      • @link nlohmann::basic_json::value value @endlink -- get a value from an object and return default value if key is not present
    • exceptions
      • @link nlohmann::basic_json::parse_error parse_error @endlink for exceptions indicating a parse error
      • @link nlohmann::basic_json::invalid_iterator invalid_iterator @endlink for exceptions indicating errors with iterators
      • @link nlohmann::basic_json::type_error type_error @endlink for exceptions indicating executing a member function with a wrong type
      • @link nlohmann::basic_json::out_of_range out_of_range @endlink for exceptions indicating access out of the defined range
      • @link nlohmann::basic_json::other_error other_error @endlink for exceptions indicating other library errors
    • lexicographical comparison operators
      • @link nlohmann::basic_json::operator== operator== @endlink
      • @link nlohmann::basic_json::operator!= operator!= @endlink
      • @link nlohmann::basic_json::operator< operator<= @endlink
      • @link nlohmann::basic_json::operator<= operator< @endlink
      • @link nlohmann::basic_json::operator> operator> @endlink
      • @link nlohmann::basic_json::operator>= operator>= @endlink
    • serialization
      • @link nlohmann::basic_json::dump dump @endlink serialize to string
      • @link nlohmann::basic_json::operator<<(std::ostream&, const basic_json &) operator<< @endlink serialize to stream
    • deserialization / parsing
      • @link nlohmann::basic_json::parse parse @endlink parse from input (string, file, etc.) and return JSON value
      • @link nlohmann::basic_json::sax_parse sax_parse @endlink parse from input (string, file, etc.) and generate SAX events
      • @link nlohmann::basic_json::operator>>(std::istream&, basic_json&) operator>> @endlink parse from stream
      • @link nlohmann::basic_json::accept accept @endlink check for syntax errors without parsing
      • @link nlohmann::json_sax SAX interface @endlink define a user-defined SAX event consumer
      • @link nlohmann::basic_json::parser_callback_t callback interface @endlink register a callback to the parse function
    • binary formats:
      • CBOR: @link nlohmann::basic_json::from_cbor from_cbor @endlink / @link nlohmann::basic_json::to_cbor to_cbor @endlink
      • MessagePack: @link nlohmann::basic_json::from_msgpack from_msgpack @endlink / @link nlohmann::basic_json::to_msgpack to_msgpack @endlink
      • UBJSON: @link nlohmann::basic_json::from_ubjson from_ubjson @endlink / @link nlohmann::basic_json::to_ubjson to_ubjson @endlink
      • BSON: @link nlohmann::basic_json::from_bson from_bson @endlink / @link nlohmann::basic_json::to_bson to_bson @endlink
  • Types
    • @link nlohmann::basic_json::array_t arrays @endlink
    • @link nlohmann::basic_json::object_t objects @endlink
    • @link nlohmann::basic_json::string_t strings @endlink
    • @link nlohmann::basic_json::boolean_t booleans @endlink
    • numbers
      • @link nlohmann::basic_json::number_integer_t signed integers @endlink
      • @link nlohmann::basic_json::number_unsigned_t unsigned integers @endlink
      • @link nlohmann::basic_json::number_float_t floating-point @endlink
  • further JSON standards
    • @link nlohmann::json_pointer JSON Pointer @endlink (REF 6901)
    • @link nlohmann::basic_json::patch JSON Patch @endlink (RFC 6902)
    • @link nlohmann::basic_json::merge_patch JSON Merge Patch @endlink (RFC 7396)

Container function overview

The container functions known from STL have been extended to support the different value types from JSON. However, not all functions can be applied to all value types. Note that the signature of some functions differ between the types; for instance, at may be called with either a string to address a key in an object or with an integer to address a value in an array.

Note that this table only lists those exceptions thrown due to the type. For instance, the @link nlohmann::basic_json::at(const typename object_t::key_type & key) at @endlink function will always throw a @link nlohmann::basic_json::type_error json::type_error @endlink exception when called for a string type. When called for an array, it may throw an @link nlohmann::basic_json::out_of_range json::out_of_range @endlink exception if the passed index is invalid.

@copyright Copyright © 2013-2019 Niels Lohmann. The code is licensed under the MIT License.

@author Niels Lohmann @see https://github.com/nlohmann/json to download the source code

@version 3.6.0