mirror of
https://github.com/nlohmann/json.git
synced 2026-07-30 23:53:02 +04:00
Compare commits
86 Commits
v1.0.0-rc1
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 80cdecaadd | |||
| d80bbffc78 | |||
| 7371c71d2a | |||
| d6b8830e03 | |||
| dc8ab92552 | |||
| 76e5e29eda | |||
| 8620583cf9 | |||
| fcbd984e0f | |||
| 70493a10d1 | |||
| 00f9296db5 | |||
| 67c2d90a21 | |||
| 4351698c83 | |||
| 9def0186be | |||
| 457bfc2401 | |||
| 1adb9d62dd | |||
| ac4d4a0f66 | |||
| 07033f67a5 | |||
| fb972e845b | |||
| 6ac89df54d | |||
| a615598b14 | |||
| 1df5d726d9 | |||
| cd04a7d3e9 | |||
| 2ba901bbf6 | |||
| 5bc1b65676 | |||
| 258f04c561 | |||
| a70a7a8001 | |||
| c767f464bb | |||
| 9da8770f3a | |||
| e0d334c4f1 | |||
| d6771ac79d | |||
| d9432aa168 | |||
| 22bc022745 | |||
| 72476b4226 | |||
| f36f316fc7 | |||
| 6f8e36ac3d | |||
| 14d8a91f73 | |||
| c013223276 | |||
| ec7a1d8347 | |||
| 3948630374 | |||
| 8f379ef3eb | |||
| 652e1caa76 | |||
| 8162a6e3a3 | |||
| 746c1a7142 | |||
| 73632377bf | |||
| 04cc7d5a05 | |||
| b342e1207c | |||
| 9d45aafc2c | |||
| 55cbd903e8 | |||
| 57de1d602e | |||
| 2550d29ded | |||
| 589dc2180a | |||
| 4eac295211 | |||
| b3ff862afc | |||
| 83d068c32c | |||
| 99261bf39c | |||
| 260745810d | |||
| 1c43789682 | |||
| 4f27004dd5 | |||
| f7fb405564 | |||
| 2d7f1542b1 | |||
| 8fdd20cdda | |||
| c6c37d00d1 | |||
| 0a81353989 | |||
| b9592bd2d6 | |||
| 067e33a7ed | |||
| bb0d01e597 | |||
| 941c84e17d | |||
| 3c8c2766c1 | |||
| 23f70b47ad | |||
| bd5d96c456 | |||
| b58a93b8dd | |||
| 6f2da1a39a | |||
| fadccc34eb | |||
| 66ec58639b | |||
| 2707733920 | |||
| b0eb34394c | |||
| 11ae6da6d9 | |||
| b431203fe8 | |||
| 2c3259320d | |||
| c910853304 | |||
| b00e627c30 | |||
| 9355dce063 | |||
| e64dc532ab | |||
| b5a05e1121 | |||
| c974e32677 | |||
| 8eb32084b4 |
+31
-28
@@ -2,31 +2,34 @@ language: cpp
|
|||||||
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
compiler:
|
# from http://stackoverflow.com/a/32127147/266378
|
||||||
- gcc
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
|
packages: ['g++-4.9', 'valgrind', 'python-pip', 'python-yaml']
|
||||||
|
before_script:
|
||||||
|
- pip install --user git+git://github.com/eddyxu/cpp-coveralls.git
|
||||||
|
env: COMPILER=g++-4.9
|
||||||
|
|
||||||
env:
|
- os: linux
|
||||||
- COMPILER=g++-4.9
|
compiler: gcc
|
||||||
- COMPILER=g++-5
|
addons:
|
||||||
- COMPILER=clang-3.6
|
apt:
|
||||||
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
|
packages: ['g++-5', 'valgrind']
|
||||||
|
env: COMPILER=g++-5
|
||||||
|
|
||||||
addons:
|
- os: linux
|
||||||
apt:
|
compiler: clang
|
||||||
sources:
|
addons:
|
||||||
- ubuntu-toolchain-r-test
|
apt:
|
||||||
- llvm-toolchain-precise
|
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
|
||||||
- llvm-toolchain-precise-3.6
|
packages: ['clang-3.6', 'valgrind']
|
||||||
- llvm-toolchain-precise-3.7
|
env: COMPILER=clang++-3.6
|
||||||
packages:
|
|
||||||
- g++-4.9
|
|
||||||
- g++-5
|
|
||||||
- clang-3.6
|
|
||||||
- valgrind
|
|
||||||
- python-pip
|
|
||||||
- python-yaml
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- pip install --user git+git://github.com/eddyxu/cpp-coveralls.git
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- make CXX=$COMPILER CXXFLAGS="-lstdc++"
|
- make CXX=$COMPILER CXXFLAGS="-lstdc++"
|
||||||
@@ -34,8 +37,8 @@ script:
|
|||||||
- valgrind --error-exitcode=1 --leak-check=full ./json_unit
|
- valgrind --error-exitcode=1 --leak-check=full ./json_unit
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- if [ "$COMPILER" = "g++-4.9" ]; make clean
|
- if [ "$COMPILER" = "g++-4.9" ]; then make clean ; fi
|
||||||
- if [ "$COMPILER" = "g++-4.9" ]; touch src/json.hpp
|
- if [ "$COMPILER" = "g++-4.9" ]; then touch src/json.hpp ; fi
|
||||||
- if [ "$COMPILER" = "g++-4.9" ]; make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER
|
- if [ "$COMPILER" = "g++-4.9" ]; then make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER ; fi
|
||||||
- if [ "$COMPILER" = "g++-4.9" ]; ./json_unit "*"
|
- if [ "$COMPILER" = "g++-4.9" ]; then ./json_unit "*" ; fi
|
||||||
- if [ "$COMPILER" = "g++-4.9" ]; coveralls --exclude test/catch.hpp --exclude test/unit.cpp --include src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9'
|
- if [ "$COMPILER" = "g++-4.9" ]; then coveralls --exclude test/catch.hpp --exclude test/unit.cpp --include src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9' ; fi
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ if(MSVC)
|
|||||||
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
|
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
|
||||||
else(MSVC)
|
else(MSVC)
|
||||||
set(CMAKE_CXX_FLAGS
|
set(CMAKE_CXX_FLAGS
|
||||||
"-std=c++11 -stdlib=libc++"
|
"-std=c++11"
|
||||||
)
|
)
|
||||||
endif(MSVC)
|
endif(MSVC)
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
.PHONY: pretty clean
|
||||||
|
|
||||||
# used programs
|
# used programs
|
||||||
RE2C = re2c
|
RE2C = re2c
|
||||||
SED = sed
|
SED = sed
|
||||||
|
|||||||
@@ -42,12 +42,15 @@ to the files you want to use JSON objects. That's it. Do not forget to set the n
|
|||||||
|
|
||||||
Though it's 2015 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
Though it's 2015 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
||||||
|
|
||||||
- GCC 4.8 - 5.2
|
- GCC 4.9 - 6.0 (and possibly later)
|
||||||
- Clang 3.4 - 3.7
|
- Clang 3.4 - 3.8 (and possibly later)
|
||||||
- Microsoft Visual C++ 14.0 RC
|
- Microsoft Visual C++ 14.0 RC (and possibly later)
|
||||||
|
|
||||||
I would be happy to learn about other compilers/versions.
|
I would be happy to learn about other compilers/versions.
|
||||||
|
|
||||||
|
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. 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
|
## Examples
|
||||||
|
|
||||||
Here are some examples to give you an idea how to use the class.
|
Here are some examples to give you an idea how to use the class.
|
||||||
@@ -169,7 +172,7 @@ You can also use streams to serialize and deserialize:
|
|||||||
```cpp
|
```cpp
|
||||||
// deserialize from standard input
|
// deserialize from standard input
|
||||||
json j;
|
json j;
|
||||||
j << std::cin;
|
std::cin >> j;
|
||||||
|
|
||||||
// serialize to standard output
|
// serialize to standard output
|
||||||
std::cout << j;
|
std::cout << j;
|
||||||
@@ -373,6 +376,16 @@ I deeply appreciate the help of the following people.
|
|||||||
- [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums.
|
- [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums.
|
||||||
- [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio.
|
- [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio.
|
||||||
- [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators.
|
- [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators.
|
||||||
|
- [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling.
|
||||||
|
- [dariomt](https://github.com/dariomt) fixed some typos in the examples.
|
||||||
|
- [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation.
|
||||||
|
- [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue.
|
||||||
|
- [Huu Nguyen](https://github.com/whoshuu) correct a variable name in the documentation.
|
||||||
|
- [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference.
|
||||||
|
- [dariomt](https://github.com/dariomt) fixed a subtlety in MSVC type support.
|
||||||
|
- [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK.
|
||||||
|
- [whackashoe](https://github.com/whackashoe) replaced a function that was marked as unsafe by Visual Studio.
|
||||||
|
- [406345](https://github.com/406345) fixed two small warnings.
|
||||||
|
|
||||||
Thanks a lot for helping out!
|
Thanks a lot for helping out!
|
||||||
|
|
||||||
@@ -385,7 +398,7 @@ $ make
|
|||||||
$ ./json_unit "*"
|
$ ./json_unit "*"
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
All tests passed (3341774 assertions in 27 test cases)
|
All tests passed (3343239 assertions in 28 test cases)
|
||||||
```
|
```
|
||||||
|
|
||||||
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).
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,5 @@
|
|||||||
version: '{build}'
|
version: '{build}'
|
||||||
os: Visual Studio 2015 RC
|
os: Visual Studio 2015
|
||||||
init: []
|
init: []
|
||||||
install: []
|
install: []
|
||||||
build_script:
|
build_script:
|
||||||
@@ -7,4 +7,5 @@ build_script:
|
|||||||
- cmake . -G "Visual Studio 14 2015"
|
- cmake . -G "Visual Studio 14 2015"
|
||||||
- cmake --build . --config Release
|
- cmake --build . --config Release
|
||||||
test_script:
|
test_script:
|
||||||
|
- Release\json_unit.exe
|
||||||
- Release\json_unit.exe "*"
|
- Release\json_unit.exe "*"
|
||||||
|
|||||||
+1
-1
@@ -121,7 +121,7 @@ USE_MDFILE_AS_MAINPAGE =
|
|||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Configuration options related to source browsing
|
# Configuration options related to source browsing
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
SOURCE_BROWSER = NO
|
SOURCE_BROWSER = YES
|
||||||
INLINE_SOURCES = NO
|
INLINE_SOURCES = NO
|
||||||
STRIP_CODE_COMMENTS = YES
|
STRIP_CODE_COMMENTS = YES
|
||||||
REFERENCED_BY_RELATION = NO
|
REFERENCED_BY_RELATION = NO
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ int main()
|
|||||||
{
|
{
|
||||||
object.at("the fast") = "il rapido";
|
object.at("the fast") = "il rapido";
|
||||||
}
|
}
|
||||||
catch (std::out_of_range)
|
catch (std::out_of_range& e)
|
||||||
{
|
{
|
||||||
std::cout << "out of range" << '\n';
|
std::cout << "out of range: " << e.what() << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/syN4hQrhPvlUy5AG"><b>online</b></a>
|
<a target="_blank" href="http://melpon.org/wandbox/permlink/3ir8W1OZ5KtbRz6r"><b>online</b></a>
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
"il brutto"
|
"il brutto"
|
||||||
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
|
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
|
||||||
out of range
|
out of range: key 'the fast' not found
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ int main()
|
|||||||
{
|
{
|
||||||
array.at(5) = "sixth";
|
array.at(5) = "sixth";
|
||||||
}
|
}
|
||||||
catch (std::out_of_range)
|
catch (std::out_of_range& e)
|
||||||
{
|
{
|
||||||
std::cout << "out of range" << '\n';
|
std::cout << "out of range: " << e.what() << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/wKBBW3ORmTHPlgJV"><b>online</b></a>
|
<a target="_blank" href="http://melpon.org/wandbox/permlink/9Ae4DO4HJjULnq5j"><b>online</b></a>
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
"third"
|
"third"
|
||||||
["first","second","third","fourth"]
|
["first","second","third","fourth"]
|
||||||
out of range
|
out of range: array index 5 is out of range
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#include <json.hpp>
|
||||||
|
|
||||||
|
using namespace nlohmann;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// create a JSON object with different entry types
|
||||||
|
json j =
|
||||||
|
{
|
||||||
|
{"integer", 1},
|
||||||
|
{"floating", 42.23},
|
||||||
|
{"string", "hello world"},
|
||||||
|
{"boolean", true},
|
||||||
|
{"object", {{"key1", 1}, {"key2", 2}}},
|
||||||
|
{"array", {1, 2, 3}}
|
||||||
|
};
|
||||||
|
|
||||||
|
// access existing values
|
||||||
|
int v_integer = j.value("integer", 0);
|
||||||
|
double v_floating = j.value("floating", 47.11);
|
||||||
|
|
||||||
|
// access nonexisting values and rely on default value
|
||||||
|
std::string v_string = j.value("nonexisting", "oops");
|
||||||
|
bool v_boolean = j.value("nonexisting", false);
|
||||||
|
|
||||||
|
// output values
|
||||||
|
std::cout << std::boolalpha << v_integer << " " << v_floating
|
||||||
|
<< " " << v_string << " " << v_boolean << "\n";
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<a target="_blank" href="http://melpon.org/wandbox/permlink/pehnjdIduvv90qfX"><b>online</b></a>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
1 42.23 oops false
|
||||||
@@ -4,7 +4,7 @@ using namespace nlohmann;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create a JSON boolean
|
// create a JSON number
|
||||||
json value = 17;
|
json value = 17;
|
||||||
|
|
||||||
// explicitly getting pointers
|
// explicitly getting pointers
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/fdsMCtY67vLJrlzv"><b>online</b></a>
|
<a target="_blank" href="http://melpon.org/wandbox/permlink/OQ6W9gVosCWDgJHS"><b>online</b></a>
|
||||||
@@ -4,7 +4,7 @@ using namespace nlohmann;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create a JSON boolean
|
// create a JSON number
|
||||||
json value = 17;
|
json value = 17;
|
||||||
|
|
||||||
// explicitly getting pointers
|
// explicitly getting pointers
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Ka7Efl5Jo2FTDy69"><b>online</b></a>
|
<a target="_blank" href="http://melpon.org/wandbox/permlink/Onaz3FY3sow5TEwH"><b>online</b></a>
|
||||||
@@ -4,13 +4,13 @@ using namespace nlohmann;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create JSON arrays
|
// create JSON objects
|
||||||
json j_no_init_list = json::object();
|
json j_no_init_list = json::object();
|
||||||
json j_empty_init_list = json::object({});
|
json j_empty_init_list = json::object({});
|
||||||
json j_list_of_pairs = json::object({ {"one", 1}, {"two", 2} });
|
json j_list_of_pairs = json::object({ {"one", 1}, {"two", 2} });
|
||||||
//json j_invalid_list = json::object({ "one", 1 }); // would throw
|
//json j_invalid_list = json::object({ "one", 1 }); // would throw
|
||||||
|
|
||||||
// serialize the JSON arrays
|
// serialize the JSON objects
|
||||||
std::cout << j_no_init_list << '\n';
|
std::cout << j_no_init_list << '\n';
|
||||||
std::cout << j_empty_init_list << '\n';
|
std::cout << j_empty_init_list << '\n';
|
||||||
std::cout << j_list_of_pairs << '\n';
|
std::cout << j_list_of_pairs << '\n';
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/kQKYwNmQRJAJhCTe"><b>online</b></a>
|
<a target="_blank" href="http://melpon.org/wandbox/permlink/wArBhgANa8p39v92"><b>online</b></a>
|
||||||
@@ -5,7 +5,7 @@ using namespace nlohmann;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create a JSON object
|
// create a JSON object
|
||||||
json object =
|
const json object =
|
||||||
{
|
{
|
||||||
{"one", 1}, {"two", 2}, {"three", 2.9}
|
{"one", 1}, {"two", 2}, {"three", 2.9}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/9X5Q8p7DlWA6v0Ey"><b>online</b></a>
|
<a target="_blank" href="http://melpon.org/wandbox/permlink/4WLxv7id8P64Q1KI"><b>online</b></a>
|
||||||
+1570
-895
File diff suppressed because it is too large
Load Diff
+1348
-700
File diff suppressed because it is too large
Load Diff
+1716
-929
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"foo": true
|
||||||
|
}
|
||||||
+1444
-24
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user