Merge branch 'release/2.0.0'

This commit is contained in:
Niels 2016-06-24 00:46:36 +02:00
commit 25ccf7f908
230 changed files with 6571 additions and 1690 deletions

View file

@ -35,7 +35,7 @@ There are currently two files which need to be edited:
To run [`re2c`](http://re2c.org) and generate/overwrite file `src/json.hpp` with your changes in file `src/json.hpp.re2c`.
2. [`test/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
@ -70,9 +70,6 @@ Please understand that I cannot accept pull requests changing only file `src/jso
The following areas really need contribution:
- Getting the code to compile without errors with the latest **Microsoft Visual Studio** version. I am not using Windows, so I cannot debug code with MSVC myself. There is a job on [AppVeyor](https://ci.appveyor.com/project/nlohmann/json) though.
- Extending the **continuous integration** beyond Linux running some versions of GCC and Clang on [Travis](https://travis-ci.org/nlohmann/json) and Microsoft Visual Studio on [AppVeyor](https://ci.appveyor.com/project/nlohmann/json). We have found a lot of bugs just because several compilers behave in a slightly different manner.
- Extending the **continuous integration** toward more exotic compilers such as Android NDK, Intel's Compiler, or the bleeding-edge versions of GCC or Clang.
- Improving the efficiency of the **JSON parser**. The current parser is implemented as a naive recursive descent parser with hand coded string handling. More sophisticated approaches like LALR parsers would be really appreciated. That said, parser generators like Bison or ANTLR do not play nice with single-header files -- I really would like to keep the parser inside the `json.hpp` header, and I am not aware of approaches similar to [`re2c`](http://re2c.org) for parsing.
- Extending and updating existing **benchmarks** to include (the most recent version of) this library. Though efficiency is not everything, speed and memory consumption are very important characteristics for C++ developers, so having proper comparisons would be interesting.
- Check the code with [**Coverity**](https://scan.coverity.com).
- Make the code **locale-independent**. The library currently only works for a locale where `.` is the decimal point character.

View file

@ -14,7 +14,7 @@ There are currently two files which need to be edited:
To run [`re2c`](http://re2c.org) and generate/overwrite file `src/json.hpp` with your changes in file `src/json.hpp.re2c`.
2. [`test/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

3
.gitignore vendored
View file

@ -9,3 +9,6 @@ working
html
me.nlohmann.json.docset
android
doc/xml

View file

@ -3,6 +3,12 @@ language: cpp
dist: trusty
sudo: required
env:
global:
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- secure: "m89SSgE+ASLO38rSKx7MTXK3n5NkP9bIx95jwY71YEiuFzib30PDJ/DifKnXxBjvy/AkCGztErQRk/8ZCvq+4HXozU2knEGnL/RUitvlwbhzfh2D4lmS3BvWBGS3N3NewoPBrRmdcvnT0xjOGXxtZaJ3P74TkB9GBnlz/HmKORA="
# from http://stackoverflow.com/a/32127147/266378
matrix:
include:
@ -19,49 +25,146 @@ matrix:
- touch src/json.hpp
- make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER
- ./json_unit "*"
- coveralls --exclude test/catch.hpp --exclude test/unit.cpp --include src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9'
- coveralls --exclude test/src/catch.hpp --exclude test/src/unit.cpp --include src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9'
- bash <(curl -s https://codecov.io/bash)
env: COMPILER=g++-4.9
- os: linux
compiler: gcc
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:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5', 'valgrind']
coverity_scan:
project:
name: "nlohmann/json"
description: "Build submitted via Travis CI"
notification_email: niels.lohmann@gmail.com
build_command_prepend: "make clean ; sudo cp $(which g++-5) $(which g++)"
build_command: "make"
branch_pattern: coverity_scan
env: COMPILER=g++-5
- os: linux
compiler: gcc
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5', 'valgrind']
env: COMPILER=g++-5
packages: ['g++-6', 'valgrind']
env: COMPILER=g++-6
# from https://github.com/travis-ci/travis-ci/issues/6120
- os: linux
compiler: clang
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
packages: ['clang-3.6', 'valgrind']
env: COMPILER=clang++-3.6
env:
- LLVM_VERSION=3.8.0
- LLVM_ARCHIVE_PATH=$HOME/clang+llvm.tar.xz
- COMPILER=clang++
- CPPFLAGS="-I $HOME/clang-$LLVM_VERSION/include/c++/v1"
- CXXFLAGS=-lc++
- PATH=$HOME/clang-$LLVM_VERSION/bin:$PATH
- LD_LIBRARY_PATH=$HOME/clang-$LLVM_VERSION/lib:$LD_LIBRARY_PATH
before_install:
- wget http://llvm.org/releases/$LLVM_VERSION/clang+llvm-$LLVM_VERSION-x86_64-linux-gnu-ubuntu-14.04.tar.xz -O $LLVM_ARCHIVE_PATH
- mkdir $HOME/clang-$LLVM_VERSION
- tar xf $LLVM_ARCHIVE_PATH -C $HOME/clang-$LLVM_VERSION --strip-components 1
- os: linux
# Clang 3.5 is not able to compile the code,
# see https://travis-ci.org/nlohmann/json/jobs/126720186
# - os: linux
# compiler: clang
# addons:
# apt:
# sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
# packages: ['clang-3.6', 'valgrind']
# env: COMPILER=clang++-3.6
#
# - os: linux
# compiler: clang
# addons:
# apt:
# sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
# packages: ['clang-3.7', 'valgrind']
# env: COMPILER=clang++-3.7
#
# - os: linux
# compiler: clang
# addons:
# apt:
# sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8']
# packages: ['clang-3.8', 'valgrind']
# env: COMPILER=clang++-3.8
# - os: linux
# compiler: clang
# addons:
# apt:
# sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise']
# packages: ['clang-3.9', 'valgrind']
# env: COMPILER=clang++-3.9
- os: osx
osx_image: beta-xcode6.1
compiler: clang
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
packages: ['clang-3.7', 'valgrind']
env: COMPILER=clang++-3.7
env:
- COMPILER=clang
- CXXFLAGS=-lstdc++
- os: osx
osx_image: beta-xcode6.2
compiler: clang
env:
- COMPILER=clang
- CXXFLAGS=-lstdc++
- os: osx
osx_image: beta-xcode6.3
compiler: clang
env:
- COMPILER=clang
- CXXFLAGS=-lstdc++
- os: osx
osx_image: xcode6.4
compiler: clang
env:
- COMPILER=clang
- CXXFLAGS=-lstdc++
- os: osx
osx_image: xcode7.1
compiler: clang
env:
- COMPILER=clang
- CXXFLAGS=-lstdc++
# - os: osx
# compiler: clang
# env: COMPILER=clang
# before_install:
# - brew update
# - brew install valgrind
- os: osx
osx_image: xcode7.2
compiler: clang
env:
- COMPILER=clang
- CXXFLAGS=-lstdc++
- os: osx
osx_image: xcode7.3
compiler: clang
env:
- COMPILER=clang
- CXXFLAGS=-lstdc++
- os: osx
osx_image: xcode8
compiler: clang
env:
- COMPILER=clang
- CXXFLAGS=-lstdc++
script:
- make CXX=$COMPILER CXXFLAGS="-lstdc++"
- uname -a
- $COMPILER --version
- make CXX=$COMPILER
- ./json_unit "*"
- valgrind --error-exitcode=1 --leak-check=full ./json_unit
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/f1196addb0e97a5ff396
on_success: change
on_failure: always
on_start: never
- if [ `which valgrind` ]; then
valgrind --error-exitcode=1 --leak-check=full ./json_unit ;
fi

View file

@ -1,25 +1,54 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.0)
project(json CXX)
# define the project
project(nlohmann_json VERSION 2.0.0 LANGUAGES CXX)
add_executable(json_unit
src/json.hpp test/catch.hpp test/unit.cpp
)
enable_testing()
if(MSVC)
set(CMAKE_CXX_FLAGS
"/EHsc"
)
option(BuildTests "Build the unit tests" ON)
STRING(REPLACE "/O2" "/Od" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
# define project variables
set(JSON_TARGET_NAME ${PROJECT_NAME})
set(JSON_PACKAGE_NAME ${JSON_TARGET_NAME})
set(JSON_TARGETS_FILENAME "${JSON_PACKAGE_NAME}Targets.cmake")
set(JSON_CONFIG_FILENAME "${JSON_PACKAGE_NAME}Config.cmake")
set(JSON_CONFIGVERSION_FILENAME "${JSON_PACKAGE_NAME}ConfigVersion.cmake")
set(JSON_CONFIG_DESTINATION "cmake")
set(JSON_INCLUDE_DESTINATION "include/nlohmann")
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
else(MSVC)
set(CMAKE_CXX_FLAGS
"-std=c++11"
)
endif(MSVC)
# create and configure the library target
add_library(${JSON_TARGET_NAME} INTERFACE)
target_include_directories(${JSON_TARGET_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${JSON_INCLUDE_DESTINATION}>)
include_directories(
src test
)
# create and configure the unit test target
if (BuildTests)
add_subdirectory(test)
endif()
# generate a config and config version file for the package
include(CMakePackageConfigHelpers)
configure_package_config_file("cmake/config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION})
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
# export the library target and store build directory in package registry
export(TARGETS ${JSON_TARGET_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/${JSON_TARGETS_FILENAME}")
export(PACKAGE ${JSON_PACKAGE_NAME})
# install library target and config files
install(TARGETS ${JSON_TARGET_NAME}
EXPORT ${JSON_PACKAGE_NAME})
install(FILES "src/json.hpp"
DESTINATION ${JSON_INCLUDE_DESTINATION})
install(EXPORT ${JSON_PACKAGE_NAME}
FILE ${JSON_TARGETS_FILENAME}
DESTINATION ${JSON_CONFIG_DESTINATION})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
DESTINATION ${JSON_CONFIG_DESTINATION})

View file

@ -5,18 +5,52 @@ All notable changes to this project will be documented in this file. This projec
[Full Changelog](https://github.com/nlohmann/json/compare/v1.1.0...HEAD)
- concatenate objects [\#252](https://github.com/nlohmann/json/issues/252)
- Unit test fails when doing a CMake out-of-tree build [\#241](https://github.com/nlohmann/json/issues/241)
- Additional integration options [\#237](https://github.com/nlohmann/json/issues/237)
- Can't use basic\_json::iterator as a base iterator for std::move\_iterator [\#233](https://github.com/nlohmann/json/issues/233)
- Provide a FAQ [\#163](https://github.com/nlohmann/json/issues/163)
- Create PULL\_REQUEST\_TEMPLATE.md [\#213](https://github.com/nlohmann/json/pull/213) ([whackashoe](https://github.com/whackashoe))
- fixed noexcept; added constexpr [\#208](https://github.com/nlohmann/json/pull/208) ([nlohmann](https://github.com/nlohmann))
- Add support for afl-fuzz testing [\#207](https://github.com/nlohmann/json/pull/207) ([mykter](https://github.com/mykter))
- Issue \#178 - Extending support to full uint64\_t/int64\_t range and unsigned type \(updated\) [\#193](https://github.com/nlohmann/json/pull/193) ([twelsby](https://github.com/twelsby))
- json::diff generates incorrect patch when removing multiple array elements. [\#269](https://github.com/nlohmann/json/issues/269)
- -Wconversion warning [\#259](https://github.com/nlohmann/json/issues/259)
- Maybe a bug [\#258](https://github.com/nlohmann/json/issues/258)
- -Wconversion warnings [\#239](https://github.com/nlohmann/json/issues/239)
- ambiguous overload for 'push\_back' and 'operator+=' [\#235](https://github.com/nlohmann/json/issues/235)
- Incorrect dumping of parsed numbers with exponents, but without decimal places [\#230](https://github.com/nlohmann/json/issues/230)
- double values are serialized with commas as decimal points [\#228](https://github.com/nlohmann/json/issues/228)
- Move semantics with std::initializer\_list [\#225](https://github.com/nlohmann/json/issues/225)
- abort during getline in yyfill [\#223](https://github.com/nlohmann/json/issues/223)
- Wrong link in the README.md [\#217](https://github.com/nlohmann/json/issues/217)
- Small bugs in json.hpp \(get\_number\) and unit.cpp \(non-standard integer type test\) [\#199](https://github.com/nlohmann/json/issues/199)
- GCC/clang floating point parsing bug in strtod\(\) [\#195](https://github.com/nlohmann/json/issues/195)
- Bugs in miloyip/nativejson-benchmark: roundtrips [\#187](https://github.com/nlohmann/json/issues/187)
- Floating point exceptions [\#181](https://github.com/nlohmann/json/issues/181)
- In basic\_json::basic\_json\(const CompatibleArrayType& val\), the requirement of CompatibleArrayType is not strict enough. [\#174](https://github.com/nlohmann/json/issues/174)
- Implicit assignment to std::string fails [\#144](https://github.com/nlohmann/json/issues/144)
- Fix Issue \#265 [\#266](https://github.com/nlohmann/json/pull/266) ([06needhamt](https://github.com/06needhamt))
- Issue \#195 - update Travis to Trusty due to gcc/clang strtod\(\) bug [\#196](https://github.com/nlohmann/json/pull/196) ([twelsby](https://github.com/twelsby))
- Compiler Errors With JSON.hpp [\#265](https://github.com/nlohmann/json/issues/265)
- VS2015 compile fail [\#260](https://github.com/nlohmann/json/issues/260)
- Error when using json in g++ [\#254](https://github.com/nlohmann/json/issues/254)
- Update long-term goals [\#246](https://github.com/nlohmann/json/issues/246)
- Error compile Android NDK error: 'strtof' is not a member of 'std' [\#219](https://github.com/nlohmann/json/issues/219)
- Conflicting typedef of ssize\_t on Windows 32 bit when using Boost.Python [\#204](https://github.com/nlohmann/json/issues/204)
- Integer conversion to unsigned [\#178](https://github.com/nlohmann/json/issues/178)
- Define CMake/CTest tests [\#247](https://github.com/nlohmann/json/pull/247) ([robertmrk](https://github.com/robertmrk))
- Out of tree builds and a few other miscellaneous CMake cleanups. [\#242](https://github.com/nlohmann/json/pull/242) ([ChrisKitching](https://github.com/ChrisKitching))
- Implement additional integration options [\#238](https://github.com/nlohmann/json/pull/238) ([robertmrk](https://github.com/robertmrk))
- make serialization locale-independent [\#232](https://github.com/nlohmann/json/pull/232) ([nlohmann](https://github.com/nlohmann))
- fixes \#223 by updating README.md [\#227](https://github.com/nlohmann/json/pull/227) ([kevin--](https://github.com/kevin--))
- Use namespace std for int64\_t and uint64\_t [\#226](https://github.com/nlohmann/json/pull/226) ([lv-zheng](https://github.com/lv-zheng))
- Added missing cerrno header to fix ERANGE compile error on android [\#222](https://github.com/nlohmann/json/pull/222) ([Teemperor](https://github.com/Teemperor))
- Corrected readme [\#218](https://github.com/nlohmann/json/pull/218) ([Annihil](https://github.com/Annihil))
- replaced ssize\_t occurrences with auto \(addresses \#204\) [\#205](https://github.com/nlohmann/json/pull/205) ([nlohmann](https://github.com/nlohmann))
- Fixed issue \#199 - Small bugs in json.hpp \(get\_number\) and unit.cpp \(non-standard integer type test\) [\#200](https://github.com/nlohmann/json/pull/200) ([twelsby](https://github.com/twelsby))
- Fix broken link [\#197](https://github.com/nlohmann/json/pull/197) ([vog](https://github.com/vog))

View file

@ -10,6 +10,7 @@ all: json_unit
# clean up
clean:
rm -fr json_unit json_benchmarks fuzz fuzz-testing *.dSYM
$(MAKE) clean -Cdoc
##########################################################################
@ -19,8 +20,8 @@ clean:
# additional flags
FLAGS = -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wfloat-equal
# build unit tests
json_unit: test/unit.cpp src/json.hpp test/catch.hpp
# build unit tests (TODO: Does this want its own makefile?)
json_unit: test/src/unit.cpp src/json.hpp test/src/catch.hpp
$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src -I test $< $(LDFLAGS) -o $@
@ -30,7 +31,7 @@ json_unit: test/unit.cpp src/json.hpp test/catch.hpp
# compile example files and check output
doctest:
make check_output -C doc
$(MAKE) check_output -C doc
##########################################################################
@ -43,11 +44,11 @@ fuzz_testing:
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
$(MAKE) fuzz CXX=afl-clang++
mv fuzz fuzz-testing
find test/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
find test/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzz"
# the fuzzer binary
fuzz: test/fuzz.cpp src/json.hpp
fuzz: test/src/fuzz.cpp src/json.hpp
$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src $< $(LDFLAGS) -o $@
@ -66,7 +67,7 @@ cppcheck:
# create scanner with re2c
re2c: src/json.hpp.re2c
$(RE2C) -b -s -i --no-generation-date $< | $(SED) '1d' > src/json.hpp
$(RE2C) -W --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp
# pretty printer
pretty:
@ -74,8 +75,8 @@ pretty:
--indent-switches --indent-preproc-block --indent-preproc-define \
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \
--align-reference=type --add-brackets --convert-tabs --close-templates \
--lineend=linux --preserve-date --suffix=none \
src/json.hpp src/json.hpp.re2c test/unit.cpp test/fuzz.cpp benchmarks/benchmarks.cpp doc/examples/*.cpp
--lineend=linux --preserve-date --suffix=none --formatted \
src/json.hpp src/json.hpp.re2c test/src/unit.cpp test/src/fuzz.cpp benchmarks/benchmarks.cpp doc/examples/*.cpp
##########################################################################

133
README.md
View file

@ -3,8 +3,9 @@
[![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)
[![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/wuiuqYiYqRTdI3rG)
[![Documentation Status](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 Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases)
[![Github Issues](https://img.shields.io/github/issues/nlohmann/json.svg)](http://github.com/nlohmann/json/issues)
@ -15,9 +16,9 @@ There are myriads of [JSON](http://json.org) libraries out there, and each may e
- **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.
- **Trivial integration**. Our whole code consists of a single header file `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.
- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks.
- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/src/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks.
Other aspects were not so important to us:
@ -27,6 +28,7 @@ Other aspects were not so important to us:
See the [contribution guidelines](https://github.com/nlohmann/json/blob/master/.github/CONTRIBUTING.md#please-dont) for more information.
## Integration
The single required source, file `json.hpp` is in the `src` directory or [released here](https://github.com/nlohmann/json/releases). All you need to do is add
@ -40,28 +42,8 @@ using json = nlohmann::json;
to the files you want to use JSON objects. That's it. Do not forget to set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang).
## Supported compilers
:beer: If you are using OS X and [Homebrew](http://brew.sh), just type `brew tap nlohmann/json` and `brew install nlohmann_json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann_json --HEAD`.
Though it's 2016 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
- GCC 4.9 - 6.0 (and possibly later)
- Clang 3.4 - 3.9 (and possibly later)
- Microsoft Visual C++ 14.0 RC (and possibly later)
I would be happy to learn about other compilers/versions.
Please note:
- GCC 4.8 does not work because of two bugs ([55817](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55817) and [57824](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57824)) in the C++11 support. Note there is a [pull request](https://github.com/nlohmann/json/pull/212) to fix some of the issues.
- Android defaults to using very old compilers and C++ libraries. To fix this, add the following to your `Application.mk`. This will switch to the LLVM C++ library, the Clang compiler, and enable C++11 and other features disabled by default.
```
APP_STL := c++_shared
NDK_TOOLCHAIN_VERSION := clang3.6
APP_CPPFLAGS += -frtti -fexceptions
```
- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MingW, please refer to [this site](http://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug.
## Examples
@ -144,6 +126,7 @@ json empty_object_explicit = json::object();
json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) };
```
### Serialization / Deserialization
You can create an object (deserialization) by appending `_json` to a string literal:
@ -152,7 +135,7 @@ You can create an object (deserialization) by appending `_json` to a string lite
// create object from string literal
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json;
// or even nicer (thanks http://isocpp.org/blog/2015/01/json-for-modern-cpp)
// or even nicer with a raw string literal
auto j2 = R"(
{
"happy": true,
@ -197,6 +180,7 @@ These operators work for any subclasses of `std::istream` or `std::ostream`.
Please note that setting the exception bit for `failbit` is inappropriate for this use case. It will result in program termination due to the `noexcept` specifier in use.
### STL-like access
We designed the JSON class to behave just like an STL container. In fact, it satisfies the [**ReversibleContainer**](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirement.
@ -264,6 +248,7 @@ int fob_present = o.count("fob"); // 0
o.erase("foo");
```
### Conversion from STL containers
Any sequence container (`std::array`, `std::vector`, `std::deque`, `std::forward_list`, `std::list`) whose values can be used to construct JSON types (e.g., integers, floating point numbers, Booleans, string types, or again STL containers described in this section) can be used to create a JSON array. The same holds for similar associative containers (`std::set`, `std::multiset`, `std::unordered_set`, `std::unordered_multiset`), but in these cases the order of the elements of the array depends how the elements are ordered in the respective STL container.
@ -326,12 +311,51 @@ json j_ummap(c_ummap); // only one entry for key "three" is used
// maybe {"one": true, "two": true, "three": true}
```
### JSON Pointer and JSON Patch
The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https://tools.ietf.org/html/rfc6902)) allows to describe differences between two JSON values - effectively allowing patch and diff operations known from Unix.
```cpp
// a JSON value
json j_original = R"({
"baz": ["one", "two", "three"],
"foo": "bar"
})"_json;
// access members with a JSON pointer (RFC 6901)
j_original["/baz/2"_json_pointer];
// "two"
// a JSON patch (RFC 6902)
json j_patch = R"([
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo"}
])"_json;
// apply the patch
json j_result = j_original.patch(j_patch);
// {
// "baz": "boo",
// "hello": ["world"]
// }
// calculate a JSON patch from two JSON values
json::diff(j_result, j_original);
// [
// { "op":" replace", "path": "/baz", "value": ["one", "two", "three"] },
// { "op":"remove","path":"/hello" },
// { "op":"add","path":"/foo","value":"bar" }
// ]
```
### Implicit conversions
The type of the JSON object is determined automatically by the expression to store. Likewise, the stored value is implicitly converted.
```cpp
/// strings
// strings
std::string s1 = "Hello, world!";
json js = s1;
std::string s2 = js;
@ -359,6 +383,51 @@ int vi = jn.get<int>();
// etc.
```
## Supported compilers
Though it's 2016 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
- GCC 4.9 - 6.0 (and possibly later)
- Clang 3.4 - 3.9 (and possibly later)
- Microsoft Visual C++ 2015 / 14.0 (and possibly later)
I would be happy to learn about other compilers/versions.
Please note:
- GCC 4.8 does not work because of two bugs ([55817](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55817) and [57824](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57824)) in the C++11 support. Note there is a [pull request](https://github.com/nlohmann/json/pull/212) to fix some of the issues.
- Android defaults to using very old compilers and C++ libraries. To fix this, add the following to your `Application.mk`. This will switch to the LLVM C++ library, the Clang compiler, and enable C++11 and other features disabled by default.
```
APP_STL := c++_shared
NDK_TOOLCHAIN_VERSION := clang3.6
APP_CPPFLAGS += -frtti -fexceptions
```
The code compiles successfully with [Android NDK](https://developer.android.com/ndk/index.html?hl=ml), Revision 9 - 11 (and possibly later) and [CrystaX's Android NDK](https://www.crystax.net/en/android/ndk) version 10.
- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](http://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https://github.com/nlohmann/json/issues/219).
The following compilers are currently used in continuous integration at [Travis](https://travis-ci.org/nlohmann/json) and [AppVeyor](https://ci.appveyor.com/project/nlohmann/json):
| Compiler | Operating System | Version String |
|-----------------|------------------------------|----------------|
| GCC 4.9.3 | Ubuntu 14.04.4 LTS | g++-4.9 (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3 |
| GCC 5.3.0 | Ubuntu 14.04.4 LTS | g++-5 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204 |
| GCC 6.1.1 | Ubuntu 14.04.4 LTS | g++-6 (Ubuntu 6.1.1-3ubuntu11~14.04.1) 6.1.1 20160511 |
| Clang 3.8.0 | Ubuntu 14.04.4 LTS | clang version 3.8.0 (tags/RELEASE_380/final) |
| Clang Xcode 6.1 | Darwin Kernel Version 13.4.0 (OSX 10.9.5) | Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) |
| Clang Xcode 6.2 | Darwin Kernel Version 13.4.0 (OSX 10.9.5) | Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn) |
| Clang Xcode 6.3 | Darwin Kernel Version 14.3.0 (OSX 10.10.3) | Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn) |
| Clang Xcode 6.4 | Darwin Kernel Version 14.3.0 (OSX 10.10.3) | Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) |
| 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.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) |
| Visual Studio 14 2015 | Windows Server 2012 R2 (x64) | Microsoft (R) Build Engine version 14.0.25123.0 |
## License
<img align="right" src="http://opensource.org/trademarks/opensource/OSI-Approved-License-100x137.png">
@ -367,11 +436,12 @@ The class is licensed under the [MIT License](http://opensource.org/licenses/MIT
Copyright &copy; 2013-2016 [Niels Lohmann](http://nlohmann.me)
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:
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.
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.
## Thanks
@ -410,14 +480,19 @@ I deeply appreciate the help of the following people.
- [Lv Zheng](https://github.com/lv-zheng) fixed a namespace issue with `int64_t` and `uint64_t`.
- [abc100m](https://github.com/abc100m) analyzed the issues with GCC 4.8 and proposed a [partial solution](https://github.com/nlohmann/json/pull/212).
- [zewt](https://github.com/zewt) added useful notes to the README file about Android.
- [Róbert Márki](https://github.com/robertmrk) added a fix to use move iterators and improved the integration via CMake.
- [Chris Kitching](https://github.com/ChrisKitching) cleaned up the CMake files.
- [Tom Needham](https://github.com/06needhamt) fixed a subtle bug with MSVC 2015 which was also proposed by [Michael K.](https://github.com/Epidal).
Thanks a lot for helping out!
## Notes
- 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).
- 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.
## Execute unit tests
To compile and run the tests, you need to execute
@ -427,7 +502,7 @@ $ make
$ ./json_unit "*"
===============================================================================
All tests passed (3344278 assertions in 29 test cases)
All tests passed (5568715 assertions in 32 test cases)
```
For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml).

View file

@ -7,5 +7,4 @@ build_script:
- cmake . -G "Visual Studio 14 2015"
- cmake --build . --config Release
test_script:
- Release\json_unit.exe
- Release\json_unit.exe "*"
- ctest -C Release -V

6
cmake/config.cmake.in Normal file
View file

@ -0,0 +1,6 @@
@PACKAGE_INIT@
cmake_policy(PUSH)
cmake_policy(SET CMP0024 OLD)
include(${CMAKE_CURRENT_LIST_DIR}/@JSON_TARGETS_FILENAME@)
cmake_policy(POP)

View file

@ -236,7 +236,7 @@ MAN_LINKS = NO
#---------------------------------------------------------------------------
# Configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
GENERATE_XML = YES
XML_OUTPUT = xml
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------

View file

@ -2,9 +2,6 @@ SRCDIR = ../src
all: doxygen
clean:
rm -fr me.nlohmann.json.docset html
##########################################################################
# example files
@ -44,6 +41,10 @@ create_links: $(EXAMPLES:.cpp=.link)
check_output: $(EXAMPLES:.cpp=.test)
clean:
rm -fr me.nlohmann.json.docset html $(EXAMPLES:.cpp=)
##########################################################################
# Doxygen HTML documentation
##########################################################################

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,35 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// create a JSON value
json j =
{
{"number", 1}, {"string", "foo"}, {"array", {1, 2}}
};
// read-only access
// output element with JSON pointer "/number"
std::cout << j.at("/number"_json_pointer) << '\n';
// output element with JSON pointer "/string"
std::cout << j.at("/string"_json_pointer) << '\n';
// output element with JSON pointer "/array"
std::cout << j.at("/array"_json_pointer) << '\n';
// output element with JSON pointer "/array/1"
std::cout << j.at("/array/1"_json_pointer) << '\n';
// writing access
// change the string
j.at("/string"_json_pointer) = "bar";
// output the changed string
std::cout << j["string"] << '\n';
// change an array element
j.at("/array/1"_json_pointer) = 21;
// output the changed array
std::cout << j["array"] << '\n';
}

View file

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

View file

@ -0,0 +1,6 @@
1
"foo"
[1,2]
2
"bar"
[1,21]

View file

@ -0,0 +1,23 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// create a JSON value
json j =
{
{"number", 1}, {"string", "foo"}, {"array", {1, 2}}
};
// read-only access
// output element with JSON pointer "/number"
std::cout << j.at("/number"_json_pointer) << '\n';
// output element with JSON pointer "/string"
std::cout << j.at("/string"_json_pointer) << '\n';
// output element with JSON pointer "/array"
std::cout << j.at("/array"_json_pointer) << '\n';
// output element with JSON pointer "/array/1"
std::cout << j.at("/array/1"_json_pointer) << '\n';
}

View file

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

View file

@ -0,0 +1,4 @@
1
"foo"
[1,2]
2

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

34
doc/examples/diff.cpp Normal file
View file

@ -0,0 +1,34 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// the source document
json source = R"(
{
"baz": "qux",
"foo": "bar"
}
)"_json;
// the target document
json target = R"(
{
"baz": "boo",
"hello": [
"world"
]
}
)"_json;
// create the patch
json patch = json::diff(source, target);
// roundtrip
json patched_source = source.patch(patch);
// output patch and roundtrip result
std::cout << std::setw(4) << patch << "\n\n"
<< std::setw(4) << patched_source << std::endl;
}

1
doc/examples/diff.link Normal file
View file

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

25
doc/examples/diff.output Normal file
View file

@ -0,0 +1,25 @@
[
{
"op": "replace",
"path": "/baz",
"value": "boo"
},
{
"op": "remove",
"path": "/foo"
},
{
"op": "add",
"path": "/hello",
"value": [
"world"
]
}
]
{
"baz": "boo",
"hello": [
"world"
]
}

View file

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

View file

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

View file

@ -1 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/7QIAVTX9fvOkHUrH"><b>online</b></a>
<a target="_blank" href="http://melpon.org/wandbox/permlink/4Fbmy4IG012HmGKs"><b>online</b></a>

View file

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

View file

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

View file

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

View file

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

View file

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

30
doc/examples/flatten.cpp Normal file
View file

@ -0,0 +1,30 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON value
json j =
{
{"pi", 3.141},
{"happy", true},
{"name", "Niels"},
{"nothing", nullptr},
{
"answer", {
{"everything", 42}
}
},
{"list", {1, 0, 2}},
{
"object", {
{"currency", "USD"},
{"value", 42.99}
}
}
};
// call flatten()
std::cout << std::setw(4) << j.flatten() << '\n';
}

View file

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

View file

@ -0,0 +1,12 @@
{
"/answer/everything": 42,
"/happy": true,
"/list/0": 1,
"/list/1": 0,
"/list/2": 2,
"/name": "Niels",
"/nothing": null,
"/object/currency": "USD",
"/object/value": 42.99,
"/pi": 3.141
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,46 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// correct JSON pointers
json::json_pointer p1;
json::json_pointer p2("");
json::json_pointer p3("/");
json::json_pointer p4("//");
json::json_pointer p5("/foo/bar");
json::json_pointer p6("/foo/bar/-");
json::json_pointer p7("/foo/~0");
json::json_pointer p8("/foo/~1");
// error: JSON pointer does not begin with a slash
try
{
json::json_pointer p9("foo");
}
catch (std::domain_error& e)
{
std::cout << "domain_error: " << e.what() << '\n';
}
// error: JSON pointer uses escape symbol ~ not followed by 0 or 1
try
{
json::json_pointer p10("/foo/~");
}
catch (std::domain_error& e)
{
std::cout << "domain_error: " << e.what() << '\n';
}
// error: JSON pointer uses escape symbol ~ not followed by 0 or 1
try
{
json::json_pointer p11("/foo/~3");
}
catch (std::domain_error& e)
{
std::cout << "domain_error: " << e.what() << '\n';
}
}

View file

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

View file

@ -0,0 +1,3 @@
domain_error: JSON pointer must be empty or begin with '/'
domain_error: escape error: '~' must be followed with '0' or '1'
domain_error: escape error: '~' must be followed with '0' or '1'

View file

@ -0,0 +1,34 @@
#include <json.hpp>
using json = nlohmann::json;
int main()
{
// different JSON Pointers
json::json_pointer ptr1("");
json::json_pointer ptr2("/foo");
json::json_pointer ptr3("/foo/0");
json::json_pointer ptr4("/");
json::json_pointer ptr5("/a~1b");
json::json_pointer ptr6("/c%d");
json::json_pointer ptr7("/e^f");
json::json_pointer ptr8("/g|h");
json::json_pointer ptr9("/i\\j");
json::json_pointer ptr10("/k\"l");
json::json_pointer ptr11("/ ");
json::json_pointer ptr12("/m~0n");
std::cout << ptr1.to_string() << '\n'
<< ptr2.to_string() << '\n'
<< ptr3.to_string() << '\n'
<< ptr4.to_string() << '\n'
<< ptr5.to_string() << '\n'
<< ptr6.to_string() << '\n'
<< ptr7.to_string() << '\n'
<< ptr8.to_string() << '\n'
<< ptr9.to_string() << '\n'
<< ptr10.to_string() << '\n'
<< ptr11.to_string() << '\n'
<< ptr12.to_string() << std::endl;
}

View file

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

View file

@ -0,0 +1,12 @@
/foo
/foo/0
/
/a~1b
/c%d
/e^f
/g|h
/i\j
/k"l
/
/m~0n

View file

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

View file

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

View file

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

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