Merge branch 'develop' into coverity_scan

This commit is contained in:
Niels Lohmann 2016-11-24 17:26:11 +01:00
commit 739f8eefb7
411 changed files with 3003611 additions and 1049 deletions

View file

@ -41,16 +41,10 @@ There are currently two files which need to be edited:
2. [`test/src/unit.cpp`](https://github.com/nlohmann/json/blob/master/test/unit.cpp) - This contains the [Catch](https://github.com/philsquared/Catch) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code. 2. [`test/src/unit.cpp`](https://github.com/nlohmann/json/blob/master/test/unit.cpp) - This contains the [Catch](https://github.com/philsquared/Catch) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code.
If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled with If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled and executed with
```sh ```sh
make make check
```
and can be executed with
```sh
./json_unit
``` ```
The test cases are also executed with several different compilers on [Travis](https://travis-ci.org/nlohmann/json) once you open a pull request. The test cases are also executed with several different compilers on [Travis](https://travis-ci.org/nlohmann/json) once you open a pull request.

View file

@ -84,22 +84,22 @@ matrix:
# Coverity (only for branch coverity_scan) # Coverity (only for branch coverity_scan)
- os: linux - os: linux
compiler: gcc compiler: clang
before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt
addons: addons:
apt: apt:
sources: ['ubuntu-toolchain-r-test'] sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5', 'valgrind'] packages: ['valgrind']
coverity_scan: coverity_scan:
project: project:
name: "nlohmann/json" name: "nlohmann/json"
description: "Build submitted via Travis CI" description: "Build submitted via Travis CI"
notification_email: niels.lohmann@gmail.com notification_email: niels.lohmann@gmail.com
build_command_prepend: "make clean ; sudo cp $(which g++-5) $(which g++)" build_command_prepend: "make clean"
build_command: "make" build_command: "make"
branch_pattern: coverity_scan branch_pattern: coverity_scan
env: env:
- COMPILER=g++-5 - LLVM_VERSION=3.6.0
- SPECIAL=coverity - SPECIAL=coverity
# OSX / Clang # OSX / Clang
@ -125,8 +125,11 @@ matrix:
- os: osx - os: osx
osx_image: xcode7.3 osx_image: xcode7.3
#- os: osx
# osx_image: xcode8
- os: osx - os: osx
osx_image: xcode8 osx_image: xcode8.1
# Linux / GCC # Linux / GCC
@ -213,6 +216,10 @@ install:
if [[ "${LLVM_VERSION}" != "" ]]; then if [[ "${LLVM_VERSION}" != "" ]]; then
LLVM_DIR=${DEPS_DIR}/llvm-${LLVM_VERSION} LLVM_DIR=${DEPS_DIR}/llvm-${LLVM_VERSION}
if [[ -z "$(ls -A ${LLVM_DIR})" ]]; then if [[ -z "$(ls -A ${LLVM_DIR})" ]]; then
travis_retry wget --quiet https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz
tar xfz cmake-3.6.1.tar.gz
(cd cmake-3.6.1 && ./configure --prefix=${LLVM_DIR}/cmake && make install)
export PATH="${LLVM_DIR}/cmake/bin:${PATH}"
LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz" LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz" LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"
LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz" LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz"

View file

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
# define the project # define the project
project(nlohmann_json VERSION 2.0.2 LANGUAGES CXX) project(nlohmann_json VERSION 2.0.7 LANGUAGES CXX)
enable_testing() enable_testing()
@ -31,7 +31,8 @@ endif()
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
configure_package_config_file("cmake/config.cmake.in" configure_package_config_file("cmake/config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION}) INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION}
PATH_VARS JSON_INCLUDE_DESTINATION)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion) COMPATIBILITY SameMajorVersion)

View file

@ -1,7 +1,51 @@
# Change Log # Change Log
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
## [v2.0.2](https://github.com/nlohmann/json/releases/tag/v2.0.2) (2016-07-30) ## [v2.0.7](https://github.com/nlohmann/json/releases/tag/v2.0.7) (2016-11-02)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.6...v2.0.7)
- ""-operators ignore the length parameter [\#340](https://github.com/nlohmann/json/issues/340)
- Check "Parsing JSON is a Minefield" [\#344](https://github.com/nlohmann/json/issues/344)
- fix minor grammar/style issue in README.md [\#336](https://github.com/nlohmann/json/pull/336) ([seeekr](https://github.com/seeekr))
## [v2.0.6](https://github.com/nlohmann/json/releases/tag/v2.0.6) (2016-10-15)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.5...v2.0.6)
- Add nested object capability to pointers [\#323](https://github.com/nlohmann/json/issues/323)
- make has\_mapped\_type struct friendly [\#324](https://github.com/nlohmann/json/pull/324) ([vpetrigo](https://github.com/vpetrigo))
- Fix usage examples' comments for std::multiset [\#322](https://github.com/nlohmann/json/issues/322)
- json\_unit runs forever when executed in build directory [\#319](https://github.com/nlohmann/json/issues/319)
- Fix usage examples' comments for std::multiset [\#321](https://github.com/nlohmann/json/pull/321) ([vasild](https://github.com/vasild))
- Include dir relocation [\#318](https://github.com/nlohmann/json/pull/318) ([ChristophJud](https://github.com/ChristophJud))
- trivial documentation fix [\#313](https://github.com/nlohmann/json/pull/313) ([5tefan](https://github.com/5tefan))
## [v2.0.5](https://github.com/nlohmann/json/releases/tag/v2.0.5) (2016-09-14)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.4...v2.0.5)
- make json\_benchmarks no longer working in 2.0.4 [\#310](https://github.com/nlohmann/json/issues/310)
## [v2.0.4](https://github.com/nlohmann/json/releases/tag/v2.0.4) (2016-09-11)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.3...v2.0.4)
- Parsing fails without space at end of file [\#306](https://github.com/nlohmann/json/issues/306)
- Unused variable warning [\#304](https://github.com/nlohmann/json/issues/304)
## [v2.0.3](https://github.com/nlohmann/json/releases/tag/v2.0.3) (2016-08-31)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.2...v2.0.3)
- Support for iterator-range parsing [\#290](https://github.com/nlohmann/json/issues/290)
- warning C4706: assignment within conditional expression [\#295](https://github.com/nlohmann/json/issues/295)
- Horribly inconsistent behavior between const/non-const reference in operator \[\] \(\) [\#289](https://github.com/nlohmann/json/issues/289)
- unit-constructor1.cpp: Fix floating point truncation warning [\#300](https://github.com/nlohmann/json/pull/300) ([t-b](https://github.com/t-b))
## [v2.0.2](https://github.com/nlohmann/json/releases/tag/v2.0.2) (2016-07-31)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.1...v2.0.2) [Full Changelog](https://github.com/nlohmann/json/compare/v2.0.1...v2.0.2)
- value\(\) does not work with \_json\_pointer types [\#283](https://github.com/nlohmann/json/issues/283) - value\(\) does not work with \_json\_pointer types [\#283](https://github.com/nlohmann/json/issues/283)
@ -108,7 +152,6 @@ All notable changes to this project will be documented in this file. This projec
- prevent json.hpp from emitting compiler warnings [\#154](https://github.com/nlohmann/json/issues/154) - prevent json.hpp from emitting compiler warnings [\#154](https://github.com/nlohmann/json/issues/154)
- json::parse\(string\) does not check utf8 bom [\#152](https://github.com/nlohmann/json/issues/152) - json::parse\(string\) does not check utf8 bom [\#152](https://github.com/nlohmann/json/issues/152)
- unsigned 64bit values output as signed [\#151](https://github.com/nlohmann/json/issues/151) - unsigned 64bit values output as signed [\#151](https://github.com/nlohmann/json/issues/151)
- Wish feature: json5 [\#150](https://github.com/nlohmann/json/issues/150)
- overload of at\(\) with default value [\#133](https://github.com/nlohmann/json/issues/133) - overload of at\(\) with default value [\#133](https://github.com/nlohmann/json/issues/133)
- Memory leak in face of exceptions [\#118](https://github.com/nlohmann/json/issues/118) - Memory leak in face of exceptions [\#118](https://github.com/nlohmann/json/issues/118)
- Find and Count for arrays [\#117](https://github.com/nlohmann/json/issues/117) - Find and Count for arrays [\#117](https://github.com/nlohmann/json/issues/117)

View file

@ -1,4 +1,4 @@
The library is licensed under the MIT License JSON for Modern C++ is licensed under the MIT License
<http://opensource.org/licenses/MIT>: <http://opensource.org/licenses/MIT>:
Copyright (c) 2013-2016 Niels Lohmann Copyright (c) 2013-2016 Niels Lohmann

View file

@ -66,13 +66,16 @@ fuzz: test/src/fuzz.cpp src/json.hpp
cppcheck: cppcheck:
cppcheck --enable=warning --inconclusive --force --std=c++11 src/json.hpp --error-exitcode=1 cppcheck --enable=warning --inconclusive --force --std=c++11 src/json.hpp --error-exitcode=1
clang_sanitize: clean
CXX=clang++ CXXFLAGS="-g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" $(MAKE)
########################################################################## ##########################################################################
# maintainer targets # maintainer targets
########################################################################## ##########################################################################
# create scanner with re2c # create scanner with re2c
re2c: src/json.hpp.re2c re2c: src/json.hpp.re2c
$(RE2C) -W --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp $(RE2C) -W --utf-8 --encoding-policy fail --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp
# pretty printer # pretty printer
pretty: pretty:
@ -92,7 +95,7 @@ pretty:
# benchmarks # benchmarks
json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp src/json.hpp json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp src/json.hpp
cd benchmarks/files/numbers ; python generate.py cd benchmarks/files/numbers ; python generate.py
$(CXX) -std=c++11 $(CXXFLAGS) -DNDEBUG -O3 -flto -I src -I benchmarks $< $(LDFLAGS) -o $@ $(CXX) -std=c++11 -pthread $(CXXFLAGS) -DNDEBUG -O3 -flto -I src -I benchmarks $< $(LDFLAGS) -o $@
./json_benchmarks ./json_benchmarks

View file

@ -1,10 +1,9 @@
[![JSON for Modern C++](https://raw.githubusercontent.com/nlohmann/json/master/doc/json.gif)](https://github.com/nlohmann/json/releases) [![JSON for Modern C++](https://raw.githubusercontent.com/nlohmann/json/master/doc/json.gif)](https://github.com/nlohmann/json/releases)
[![Build Status](https://travis-ci.org/nlohmann/json.svg?branch=master)](https://travis-ci.org/nlohmann/json) [![Build Status](https://travis-ci.org/nlohmann/json.svg?branch=master)](https://travis-ci.org/nlohmann/json)
[![Build Status](https://ci.appveyor.com/api/projects/status/1acb366xfyg3qybk?svg=true)](https://ci.appveyor.com/project/nlohmann/json) [![Build Status](https://ci.appveyor.com/api/projects/status/1acb366xfyg3qybk/branch/develop?svg=true)](https://ci.appveyor.com/project/nlohmann/json)
[![Coverage Status](https://img.shields.io/coveralls/nlohmann/json.svg)](https://coveralls.io/r/nlohmann/json) [![Coverage Status](https://img.shields.io/coveralls/nlohmann/json.svg)](https://coveralls.io/r/nlohmann/json)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/5550/badge.svg)](https://scan.coverity.com/projects/nlohmann-json) [![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/fsf5FqYe6GoX68W6)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/p5o4znPnGHJpDVqN)
[![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://nlohmann.github.io/json) [![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://nlohmann.github.io/json)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
[![Github Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases) [![Github Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases)
@ -15,7 +14,7 @@
There are myriads of [JSON](http://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals: There are myriads of [JSON](http://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:
- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you know, what I mean. - **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean.
- **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/src/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. - **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/src/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings.
@ -284,8 +283,8 @@ json j_uset(c_uset); // only one entry for "one" is used
// maybe ["two", "three", "four", "one"] // maybe ["two", "three", "four", "one"]
std::multiset<std::string> c_mset {"one", "two", "one", "four"}; std::multiset<std::string> c_mset {"one", "two", "one", "four"};
json j_mset(c_mset); // only one entry for "one" is used json j_mset(c_mset); // both entries for "one" are used
// maybe ["one", "two", "four"] // maybe ["one", "two", "one", "four"]
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"}; std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
json j_umset(c_umset); // both entries for "one" are used json j_umset(c_umset); // both entries for "one" are used
@ -431,7 +430,7 @@ The following compilers are currently used in continuous integration at [Travis]
| Clang Xcode 7.1 | Darwin Kernel Version 14.5.0 (OSX 10.10.5) | Apple LLVM version 7.0.0 (clang-700.1.76) | | Clang Xcode 7.1 | Darwin Kernel Version 14.5.0 (OSX 10.10.5) | Apple LLVM version 7.0.0 (clang-700.1.76) |
| Clang Xcode 7.2 | Darwin Kernel Version 15.0.0 (OSX 10.10.5) | Apple LLVM version 7.0.2 (clang-700.1.81) | | Clang Xcode 7.2 | Darwin Kernel Version 15.0.0 (OSX 10.10.5) | Apple LLVM version 7.0.2 (clang-700.1.81) |
| Clang Xcode 7.3 | Darwin Kernel Version 15.0.0 (OSX 10.10.5) | Apple LLVM version 7.3.0 (clang-703.0.29) | | Clang Xcode 7.3 | Darwin Kernel Version 15.0.0 (OSX 10.10.5) | Apple LLVM version 7.3.0 (clang-703.0.29) |
| Clang Xcode 8.0 | Darwin Kernel Version 15.5.0 (OSX 10.11.5) | Apple LLVM version 8.0.0 (clang-800.0.24.1) | | Clang Xcode 8.1 | Darwin Kernel Version 16.1.0 (macOS 10.12.1) | Apple LLVM version 8.0.0 (clang-800.0.42.1) |
| Visual Studio 14 2015 | Windows Server 2012 R2 (x64) | Microsoft (R) Build Engine version 14.0.25123.0 | | Visual Studio 14 2015 | Windows Server 2012 R2 (x64) | Microsoft (R) Build Engine version 14.0.25123.0 |
@ -493,6 +492,15 @@ I deeply appreciate the help of the following people.
- [Mário Feroldi](https://github.com/thelostt) fixed a small typo. - [Mário Feroldi](https://github.com/thelostt) fixed a small typo.
- [duncanwerner](https://github.com/duncanwerner) found a really embarrassing performance regression in the 2.0.0 release. - [duncanwerner](https://github.com/duncanwerner) found a really embarrassing performance regression in the 2.0.0 release.
- [Damien](https://github.com/dtoma) fixed one of the last conversion warnings. - [Damien](https://github.com/dtoma) fixed one of the last conversion warnings.
- [Thomas Braun](https://github.com/t-b) fixed a warning in a test case.
- [Théo DELRIEU](https://github.com/theodelrieu) patiently and constructively oversaw the long way toward [iterator-range parsing](https://github.com/nlohmann/json/issues/290).
- [Stefan](https://github.com/5tefan) fixed a minor issue in the documentation.
- [Vasil Dimov](https://github.com/vasild) fixed the documentation regarding conversions from `std::multiset`.
- [ChristophJud](https://github.com/ChristophJud) overworked the CMake files to ease project inclusion.
- [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable.
- [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file.
- [Pierre-Antoine Lacaze](https://github.com/palacaze) found a subtle bug in the `dump()` function.
- [TurpentineDistillery](https://github.com/TurpentineDistillery) pointed to [`std::locale::classic()`](http://en.cppreference.com/w/cpp/locale/locale/classic) to avoid too much locale joggling.
Thanks a lot for helping out! Thanks a lot for helping out!
@ -501,6 +509,11 @@ Thanks a lot for helping out!
- The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert). In particular, note [`operator[]`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html#a2e26bd0b0168abb61f67ad5bcd5b9fa1) implements **unchecked access** for const objects: If the given key is not present, the behavior is undefined (think of a dereferenced null pointer) and yields an [assertion failure](https://github.com/nlohmann/json/issues/289) if assertions are switched on. If you are not sure whether an element in an object exists, use checked access with the [`at()` function](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html#a674de1ee73e6bf4843fc5dc1351fb726). - The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert). In particular, note [`operator[]`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html#a2e26bd0b0168abb61f67ad5bcd5b9fa1) implements **unchecked access** for const objects: If the given key is not present, the behavior is undefined (think of a dereferenced null pointer) and yields an [assertion failure](https://github.com/nlohmann/json/issues/289) if assertions are switched on. If you are not sure whether an element in an object exists, use checked access with the [`at()` function](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html#a674de1ee73e6bf4843fc5dc1351fb726).
- As the exact type of a number is not defined in the [JSON specification](http://rfc7159.net/rfc7159), this library tries to choose the best fitting C++ number type automatically. As a result, the type `double` may be used to store numbers which may yield [**floating-point exceptions**](https://github.com/nlohmann/json/issues/181) in certain rare situations if floating-point exceptions have been unmasked in the calling code. These exceptions are not caused by the library and need to be fixed in the calling code, such as by re-masking the exceptions prior to calling library functions. - As the exact type of a number is not defined in the [JSON specification](http://rfc7159.net/rfc7159), this library tries to choose the best fitting C++ number type automatically. As a result, the type `double` may be used to store numbers which may yield [**floating-point exceptions**](https://github.com/nlohmann/json/issues/181) in certain rare situations if floating-point exceptions have been unmasked in the calling code. These exceptions are not caused by the library and need to be fixed in the calling code, such as by re-masking the exceptions prior to calling library functions.
- The library supports **Unicode input** as follows:
- Only **UTF-8** encoded input is supported which is the default encoding for JSON according to [RFC 7159](http://rfc7159.net/rfc7159#rfc.section.8.1).
- Other encodings such as Latin-1, UTF-16, or UTF-32 are not supported and will yield parse errors.
- [Unicode noncharacters](http://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library.
- Invalid surrogates (e.g., incomplete pairs such as `\uDEAD`) will yield parse errors.
## Execute unit tests ## Execute unit tests
@ -511,7 +524,17 @@ To compile and run the tests, you need to execute
$ make check $ make check
=============================================================================== ===============================================================================
All tests passed (8905099 assertions in 32 test cases) All tests passed (8905491 assertions in 36 test cases)
```
Alternatively, you can use [CMake](https://cmake.org) and run
```sh
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ctest
``` ```
For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml). For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml).

View file

@ -3,14 +3,36 @@
#include <fstream> #include <fstream>
#include <benchpress.hpp> #include <benchpress.hpp>
#include <json.hpp> #include <json.hpp>
#include <pthread.h>
#include <thread>
struct StartUp
{
StartUp()
{
#ifndef __llvm__
// pin thread to a single CPU
cpu_set_t cpuset;
pthread_t thread;
thread = pthread_self();
CPU_ZERO(&cpuset);
CPU_SET(std::thread::hardware_concurrency() - 1, &cpuset);
pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
#endif
}
};
StartUp startup;
BENCHMARK("parse jeopardy.json", [](benchpress::context* ctx) BENCHMARK("parse jeopardy.json", [](benchpress::context* ctx)
{ {
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->stop_timer();
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json"); std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json");
nlohmann::json j; nlohmann::json j;
ctx->start_timer();
j << input_file; j << input_file;
ctx->stop_timer();
} }
}) })
@ -18,9 +40,12 @@ BENCHMARK("parse canada.json", [](benchpress::context* ctx)
{ {
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->stop_timer();
std::ifstream input_file("benchmarks/files/nativejson-benchmark/canada.json"); std::ifstream input_file("benchmarks/files/nativejson-benchmark/canada.json");
nlohmann::json j; nlohmann::json j;
ctx->start_timer();
j << input_file; j << input_file;
ctx->stop_timer();
} }
}) })
@ -28,9 +53,12 @@ BENCHMARK("parse citm_catalog.json", [](benchpress::context* ctx)
{ {
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->stop_timer();
std::ifstream input_file("benchmarks/files/nativejson-benchmark/citm_catalog.json"); std::ifstream input_file("benchmarks/files/nativejson-benchmark/citm_catalog.json");
nlohmann::json j; nlohmann::json j;
ctx->start_timer();
j << input_file; j << input_file;
ctx->stop_timer();
} }
}) })
@ -38,9 +66,12 @@ BENCHMARK("parse twitter.json", [](benchpress::context* ctx)
{ {
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->stop_timer();
std::ifstream input_file("benchmarks/files/nativejson-benchmark/twitter.json"); std::ifstream input_file("benchmarks/files/nativejson-benchmark/twitter.json");
nlohmann::json j; nlohmann::json j;
ctx->start_timer();
j << input_file; j << input_file;
ctx->stop_timer();
} }
}) })
@ -48,9 +79,12 @@ BENCHMARK("parse numbers/floats.json", [](benchpress::context* ctx)
{ {
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->stop_timer();
std::ifstream input_file("benchmarks/files/numbers/floats.json"); std::ifstream input_file("benchmarks/files/numbers/floats.json");
nlohmann::json j; nlohmann::json j;
ctx->start_timer();
j << input_file; j << input_file;
ctx->stop_timer();
} }
}) })
@ -58,9 +92,12 @@ BENCHMARK("parse numbers/signed_ints.json", [](benchpress::context* ctx)
{ {
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->stop_timer();
std::ifstream input_file("benchmarks/files/numbers/signed_ints.json"); std::ifstream input_file("benchmarks/files/numbers/signed_ints.json");
nlohmann::json j; nlohmann::json j;
ctx->start_timer();
j << input_file; j << input_file;
ctx->stop_timer();
} }
}) })
@ -68,9 +105,12 @@ BENCHMARK("parse numbers/unsigned_ints.json", [](benchpress::context* ctx)
{ {
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->stop_timer();
std::ifstream input_file("benchmarks/files/numbers/unsigned_ints.json"); std::ifstream input_file("benchmarks/files/numbers/unsigned_ints.json");
nlohmann::json j; nlohmann::json j;
ctx->start_timer();
j << input_file; j << input_file;
ctx->stop_timer();
} }
}) })
@ -84,7 +124,9 @@ BENCHMARK("dump jeopardy.json", [](benchpress::context* ctx)
ctx->reset_timer(); ctx->reset_timer();
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->start_timer();
output_file << j; output_file << j;
ctx->stop_timer();
} }
std::remove("jeopardy.dump.json"); std::remove("jeopardy.dump.json");
@ -100,7 +142,9 @@ BENCHMARK("dump jeopardy.json with indent", [](benchpress::context* ctx)
ctx->reset_timer(); ctx->reset_timer();
for (size_t i = 0; i < ctx->num_iterations(); ++i) for (size_t i = 0; i < ctx->num_iterations(); ++i)
{ {
ctx->start_timer();
output_file << std::setw(4) << j; output_file << std::setw(4) << j;
ctx->stop_timer();
} }
std::remove("jeopardy.dump.json"); std::remove("jeopardy.dump.json");

View file

@ -1,6 +1,7 @@
@PACKAGE_INIT@ @PACKAGE_INIT@
set_and_check(JSON_INCLUDE_DIR "@PACKAGE_JSON_INCLUDE_DESTINATION@")
cmake_policy(PUSH) cmake_policy(PUSH)
cmake_policy(SET CMP0024 OLD) cmake_policy(SET CMP0024 OLD)
include(${CMAKE_CURRENT_LIST_DIR}/@JSON_TARGETS_FILENAME@) include(${CMAKE_CURRENT_LIST_DIR}/@JSON_TARGETS_FILENAME@)
cmake_policy(POP) cmake_policy(POP)

View file

@ -5,7 +5,7 @@
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8 DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "JSON for Modern C++" PROJECT_NAME = "JSON for Modern C++"
PROJECT_NUMBER = 2.0.2 PROJECT_NUMBER = 2.0.7
PROJECT_BRIEF = PROJECT_BRIEF =
PROJECT_LOGO = PROJECT_LOGO =
OUTPUT_DIRECTORY = . OUTPUT_DIRECTORY = .

View file

@ -1 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/p5o4znPnGHJpDVqN"><b>online</b></a> <a target="_blank" href="http://melpon.org/wandbox/permlink/fsf5FqYe6GoX68W6"><b>online</b></a>

View file

@ -1,12 +0,0 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// create a JSON value with default null value
json j;
// serialize the JSON null value
std::cout << j << '\n';
}

View file

@ -1 +0,0 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/dRptmFmhvpsYB49t"><b>online</b></a>

View file

@ -1 +0,0 @@
null

View file

@ -39,7 +39,7 @@ int main()
// create an array from std::multiset // create an array from std::multiset
std::multiset<std::string> c_mset {"one", "two", "one", "four"}; std::multiset<std::string> c_mset {"one", "two", "one", "four"};
json j_mset(c_mset); // only one entry for "one" is used json j_mset(c_mset); // both entries for "one" are used
// create an array from std::unordered_multiset // create an array from std::unordered_multiset
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"}; std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};

View file

@ -1 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/MghSilgvyh4ZJShY"><b>online</b></a> <a target="_blank" href="http://melpon.org/wandbox/permlink/3BIhBw91FUVuHE1D"><b>online</b></a>

View file

@ -27,7 +27,8 @@ int main()
ss << text; ss << text;
// create JSON from stream // create JSON from stream
json j_complete(ss); json j_complete(ss); // deprecated!
// shall be replaced by: json j_complete = json::parse(ss);
std::cout << std::setw(4) << j_complete << "\n\n"; std::cout << std::setw(4) << j_complete << "\n\n";
@ -51,5 +52,6 @@ int main()
// create JSON from stream (with callback) // create JSON from stream (with callback)
json j_filtered(ss, cb); json j_filtered(ss, cb);
// shall be replaced by: json j_filtered = json::parse(ss, cb);
std::cout << std::setw(4) << j_filtered << '\n'; std::cout << std::setw(4) << j_filtered << '\n';
} }

View file

@ -1 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/VzSqLszbnoWE92dD"><b>online</b></a> <a target="_blank" href="http://melpon.org/wandbox/permlink/R6dzpKXlxrttShf7"><b>online</b></a>

View file

@ -4,9 +4,12 @@ using json = nlohmann::json;
int main() int main()
{ {
// create a JSON null value // implicitly create a JSON null value
json j(nullptr); json j1;
// explicitly create a JSON null value
json j2(nullptr);
// serialize the JSON null value // serialize the JSON null value
std::cout << j << '\n'; std::cout << j1 << '\n' << j2 << '\n';
} }

View file

@ -1 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/PMMpoM0ujdJDsuta"><b>online</b></a> <a target="_blank" href="http://melpon.org/wandbox/permlink/9Tvfs2dJBW8m8ihA"><b>online</b></a>

View file

@ -1 +1,2 @@
null null
null

View file

@ -40,7 +40,7 @@ int main()
// output the changed array // output the changed array
std::cout << j["array"] << '\n'; std::cout << j["array"] << '\n';
// "change" the arry element past the end // "change" the array element past the end
j["/array/-"_json_pointer] = 55; j["/array/-"_json_pointer] = 55;
// output the changed array // output the changed array
std::cout << j["array"] << '\n'; std::cout << j["array"] << '\n';

View file

@ -1 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/xzFX3E4gYBXFwd04"><b>online</b></a> <a target="_blank" href="http://melpon.org/wandbox/permlink/AYgVTzCodPApT4hT"><b>online</b></a>

View file

@ -0,0 +1,28 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// a JSON text
char text[] = R"(
{
"Image": {
"Width": 800,
"Height": 600,
"Title": "View from 15th Floor",
"Thumbnail": {
"Url": "http://www.example.com/image/481989943",
"Height": 125,
"Width": 100
},
"Animated" : false,
"IDs": [116, 943, 234, 38793]
}
}
)";
// parse and serialize JSON
json j_complete = json::parse(text);
std::cout << std::setw(4) << j_complete << "\n\n";
}

View file

@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/CwZnqGqte14SYJ5s"><b>online</b></a>

View file

@ -0,0 +1,20 @@
{
"Image": {
"Animated": false,
"Height": 600,
"IDs": [
116,
943,
234,
38793
],
"Thumbnail": {
"Height": 125,
"Url": "http://www.example.com/image/481989943",
"Width": 100
},
"Title": "View from 15th Floor",
"Width": 800
}
}

View file

@ -0,0 +1,13 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// a JSON text given as std::vector
std::vector<uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
// parse and serialize JSON
json j_complete = json::parse(text);
std::cout << std::setw(4) << j_complete << "\n\n";
}

View file

@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/F8VaVFyys87qQRt5"><b>online</b></a>

View file

@ -0,0 +1,6 @@
[
1,
2,
3
]

View file

@ -0,0 +1,13 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// a JSON text given as std::vector
std::vector<uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
// parse and serialize JSON
json j_complete = json::parse(text.begin(), text.end());
std::cout << std::setw(4) << j_complete << "\n\n";
}

View file

@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/ojh4Eeol4G9RgeRV"><b>online</b></a>

View file

@ -0,0 +1,6 @@
[
1,
2,
3
]

View file

@ -5,7 +5,7 @@ using json = nlohmann::json;
int main() int main()
{ {
// a JSON text // a JSON text
std::string text = R"( auto text = R"(
{ {
"Image": { "Image": {
"Width": 800, "Width": 800,
@ -44,4 +44,4 @@ int main()
// parse (with callback) and serialize JSON // parse (with callback) and serialize JSON
json j_filtered = json::parse(text, cb); json j_filtered = json::parse(text, cb);
std::cout << std::setw(4) << j_filtered << '\n'; std::cout << std::setw(4) << j_filtered << '\n';
} }

View file

@ -1 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/SrKpkE9ivmvd2OUy"><b>online</b></a> <a target="_blank" href="http://melpon.org/wandbox/permlink/n888UNQlMFduURhE"><b>online</b></a>

BIN
doc/images/scanner.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 KiB

View file

@ -268,4 +268,4 @@ The container functions known from STL have been extended to support the differe
@author [Niels Lohmann](http://nlohmann.me) @author [Niels Lohmann](http://nlohmann.me)
@see https://github.com/nlohmann/json to download the source code @see https://github.com/nlohmann/json to download the source code
@version 2.0.2 @version 2.0.7

Binary file not shown.

Before

Width:  |  Height:  |  Size: 440 KiB

After

Width:  |  Height:  |  Size: 444 KiB

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Nicolas Seriot
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1 @@
[-1e+9999]

View file

@ -0,0 +1 @@
[1.5e+9999]

View file

@ -0,0 +1 @@
{"\uDFAA":0}

View file

@ -0,0 +1 @@
["\ud800abc"]

View file

@ -0,0 +1 @@
["譌・ム淫"]

View file

@ -0,0 +1 @@
["\uDd1ea"]

View file

@ -0,0 +1 @@
["\uD800\uD800\n"]

View file

@ -0,0 +1 @@
["\uDd1e\uD834"]

View file

@ -0,0 +1 @@
["<22><><EFBFBD><EFBFBD>"]

View file

@ -0,0 +1 @@
["<22><>"]

View file

@ -0,0 +1 @@
["\uDBFF\uDFFE"]

View file

@ -0,0 +1 @@
["\uD83F\uDFFE"]

View file

@ -0,0 +1 @@
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

View file

@ -0,0 +1 @@
[a

View file

@ -0,0 +1 @@
[,1]

View file

@ -0,0 +1 @@
[1,,2]

View file

@ -0,0 +1 @@
["x"]]

View file

@ -0,0 +1 @@
["",]

View file

@ -0,0 +1 @@
["x"

View file

@ -0,0 +1 @@
[<EFBFBD>]

View file

@ -0,0 +1 @@
[,]

View file

@ -0,0 +1 @@
[-]

View file

@ -0,0 +1 @@
[ , ""]

View file

@ -0,0 +1,3 @@
["a",
4
,1,

View file

@ -0,0 +1 @@
[1,]

View file

@ -0,0 +1 @@
[*]

View file

@ -0,0 +1 @@
[""

View file

@ -0,0 +1 @@
[fals]

View file

@ -0,0 +1 @@
[nul]

View file

@ -0,0 +1 @@
[tru]

View file

@ -0,0 +1 @@
[++1234]

View file

@ -0,0 +1 @@
[+1]

View file

@ -0,0 +1 @@
[+Inf]

View file

@ -0,0 +1 @@
[-01]

View file

@ -0,0 +1 @@
[-1.0.]

View file

@ -0,0 +1 @@
[-2.]

View file

@ -0,0 +1 @@
[-NaN]

View file

@ -0,0 +1 @@
[.-1]

View file

@ -0,0 +1 @@
[.2e-3]

View file

@ -0,0 +1 @@
[0.1.2]

Some files were not shown because too many files have changed in this diff Show more