From 772bb3cc209ecffc17a1a530842d219431734dfd Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 10 Dec 2017 12:32:20 +0100 Subject: [PATCH 1/2] :memo: fixing documentation #867 The example in the documentation on how to "force" an array of arrays was wrong since the first release. Fixed the documentation and added checks for the README unit tests. --- README.md | 2 +- src/json.hpp | 12 ++++++------ test/src/unit-readme.cpp | 9 ++++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6e13bfdc..c4d9f733 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ json empty_object_implicit = json({}); json empty_object_explicit = json::object(); // a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]] -json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) }; +json array_not_object = json::array({ {"currency", "USD"}, {"value", 42.99} }); ``` diff --git a/src/json.hpp b/src/json.hpp index 23d42054..e0466b68 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -3646,12 +3646,12 @@ class iter_impl public: - /// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. - /// The C++ Standard has never required user-defined iterators to derive from std::iterator. - /// A user-defined iterator should provide publicly accessible typedefs named - /// iterator_category, value_type, difference_type, pointer, and reference. - /// Note that value_type is required to be non-const, even for constant iterators. - using iterator_category = std::bidirectional_iterator_tag; + /// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. + /// The C++ Standard has never required user-defined iterators to derive from std::iterator. + /// A user-defined iterator should provide publicly accessible typedefs named + /// iterator_category, value_type, difference_type, pointer, and reference. + /// Note that value_type is required to be non-const, even for constant iterators. + using iterator_category = std::bidirectional_iterator_tag; /// the type of the values when the iterator is dereferenced using value_type = typename BasicJsonType::value_type; diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index bc159775..1ce6ee1d 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -100,13 +100,20 @@ TEST_CASE("README", "[hide]") { // ways to express the empty array [] json empty_array_implicit = {{}}; + CHECK(empty_array_implicit.is_array()); json empty_array_explicit = json::array(); + CHECK(empty_array_explicit.is_array()); // a way to express the empty object {} json empty_object_explicit = json::object(); + CHECK(empty_object_explicit.is_object()); // a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]] - json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) }; + json array_not_object = json::array({ {"currency", "USD"}, {"value", 42.99} }); + CHECK(array_not_object.is_array()); + CHECK(array_not_object.size() == 2); + CHECK(array_not_object[0].is_array()); + CHECK(array_not_object[1].is_array()); } { From 7de009edd1b904dceb4307fca1d06b1f525c4b71 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 10 Dec 2017 13:07:47 +0100 Subject: [PATCH 2/2] :pencil2: fixing typos #869 --- src/json.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index e0466b68..f353fddd 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -227,7 +227,7 @@ class exception : public std::exception /*! @brief exception indicating a parse error -This excpetion is thrown by the library when a parse error occurs. Parse errors +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. @@ -243,7 +243,7 @@ json.exception.parse_error.102 | parse error at 14: missing or wrong low surroga 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](https://tools.ietf.org/html/rfc6902) 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](https://tools.ietf.org/html/rfc6901)) may be `0` or any number wihtout a leading `0`. +json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) 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. @@ -3294,7 +3294,7 @@ class parser } /*! - @brief the acutal acceptor + @brief the actual acceptor @invariant 1. The last token is not yet processed. Therefore, the caller of this function must make sure a token has been read. @@ -4312,7 +4312,7 @@ class json_reverse_iterator : public std::reverse_iterator { public: using difference_type = std::ptrdiff_t; - /// shortcut to the reverse iterator adaptor + /// shortcut to the reverse iterator adapter using base_iterator = std::reverse_iterator; /// the reference type for the pointed-to element using reference = typename Base::reference; @@ -8304,7 +8304,7 @@ class basic_json @brief create a JSON value This is a "catch all" constructor for all compatible JSON types; that is, - types for which a `to_json()` method exsits. The constructor forwards the + types for which a `to_json()` method exists. The constructor forwards the parameter @a val to that method (to `json_serializer::to_json` method with `U = uncvref_t`, to be exact). @@ -9027,7 +9027,7 @@ class basic_json string | value_t::string number (integer) | value_t::number_integer number (unsigned integer) | value_t::number_unsigned - number (foating-point) | value_t::number_float + number (floating-point) | value_t::number_float object | value_t::object array | value_t::array discarded | value_t::discarded @@ -10366,7 +10366,7 @@ class basic_json @return copy of the element at key @a key or @a default_value if @a key is not found - @throw type_error.306 if the JSON value is not an objec; in that cases, + @throw type_error.306 if the JSON value is not an object; in that cases, using `value()` with a key makes no sense. @complexity Logarithmic in the size of the container.