Skip to content

JSON for Modern C++ Version 2.0.0

Compare
Choose a tag to compare
@nlohmann nlohmann released this 23 Jun 22:51
· 3635 commits to master since this release
  • Release date: 2016-06-24
  • SHA-256: ac9e1fb25c2ac9ca5fc501fcd2fe3281fe04f07018a1b48820e7b1b11491bb6c

Summary

This release adds several features such as JSON Pointers, JSON Patch, or support for 64 bit unsigned integers. Furthermore, several (subtle) bugs have been fixed.

As noexcept and constexpr specifier have been added to several functions, the public API has effectively been changed in a (potential) non-backwards compatible manner. As we adhere to Semantic Versioning, this calls for a new major version, so say hello to 2️⃣.0️⃣.0️⃣.

Changes

  • 🔟 A JSON value now uses uint64_t (default value for template parameter NumberUnsignedType) as data type for unsigned integer values. This type is used automatically when an unsigned number is parsed. Furthermore, constructors, conversion operators and an is_number_unsigned() test have been added.
  • 👉 JSON Pointer (RFC 6901) support: A JSON Pointer is a string (similar to an XPath expression) to address a value inside a structured JSON value. JSON Pointers can be used in at() and operator[] functions. Furthermore, JSON values can be “flattened” to key/value pairs using flatten() where each key is a JSON Pointer. The original value can be restored by “unflattening” the flattened value using unflatten().
  • 🏥 JSON Patch (RFC 6902) support. A JSON Patch is a JSON value that describes the required edit operations (add, change, remove, …) to transform a JSON value into another one. A JSON Patch can be created with function diff(const basic_json&) and applied with patch(const basic_json&). Note the created patches use a rather primitive algorithm so far and leave room for improvement.
  • 🇪🇺 The code is now locale-independent: Floating-point numbers are always serialized with a period (.) as decimal separator and ignores different settings from the locale.
  • 🍺 Homebrew support: Install the library with brew tap nlohmann/json && brew install nlohmann_json.
  • Added constructor to create a JSON value by parsing a std::istream (e.g., std::stringstream or std::ifstream).
  • Added noexcept specifier to basic_json(boolean_t), basic_json(const number_integer_t), basic_json(const int), basic_json(const number_float_t), iterator functions (begin(), end(), etc.)
  • When parsing numbers, the sign of 0.0 (vs. -0.0) is preserved.
  • Improved MSVC 2015, Android, and MinGW support. See README for more information.
  • Improved test coverage (added 2,225,386 tests).
  • Removed some misuses of std::move.
  • Fixed several compiler warnings.
  • Improved error messages from JSON parser.
  • Updated to re2c to version 0.16 to use a minimal DFAs for the lexer.
  • Updated test suite to use Catch version 1.5.6.
  • Made type getters (is_number, etc.) and const value access constexpr.
  • Functions push_back and operator+= now work with key/value pairs passed as initializer list, e.g. j_object += {"key", 1}.
  • Overworked CMakeLists.txt to make it easier to integrate the library into other projects.

Notes

  • Parser error messages are still very vague and contain no information on the error location.
  • The implemented diff function is rather primitive and does not create minimal diffs.
  • The name of function iteration_wrapper may change in the future and the function will be deprecated in the next release.
  • Roundtripping (i.e., parsing a JSON value from a string, serializing it, and comparing the strings) of floating-point numbers is not 100% accurate. Note that RFC 7159 defines no format to internally represent numbers and states not requirement for roundtripping. Nevertheless, benchmarks like Native JSON Benchmark treat roundtripping deviations as conformance errors.