1
0
mirror of https://github.com/nlohmann/json.git synced 2026-07-25 21:23:02 +04:00

Compare commits

..

86 Commits

Author SHA1 Message Date
Niels 80cdecaadd fixed a cppcheck warning 2015-12-27 18:07:21 +01:00
Niels d80bbffc78 minor cleanup 2015-12-27 17:58:36 +01:00
Niels 7371c71d2a using CHECK_THROWS_WITH to check exceptions (#160) 2015-12-27 15:30:30 +01:00
Niels d6b8830e03 more work on exceptions (#160) 2015-12-26 13:17:32 +01:00
Niels dc8ab92552 more tests for exceptions (#160) 2015-12-25 13:04:40 +01:00
Niels 76e5e29eda overworked exceptions and tests (#160) 2015-12-25 11:46:18 +01:00
Niels 8620583cf9 cleanup 2015-12-23 12:05:57 +01:00
Niels fcbd984e0f cleanup 2015-12-23 08:44:34 +01:00
Niels 70493a10d1 iterator_wrapper for const objects (#83) 2015-12-23 08:21:29 +01:00
Niels 00f9296db5 some cleanup for #83 2015-12-22 18:07:51 +01:00
Niels 67c2d90a21 working on #160 2015-12-22 13:27:40 +01:00
Niels 4351698c83 re-adding const version operator[] (#135, #159)
It was a good idea to implement a const version of operator[] it in the
first place. I was a pity that this implementation was flawed. It was a
mistake to remove the const version completely. This commit
re-introduces the const version. My apologies for all the inconvenience.
2015-12-21 08:42:42 +01:00
Niels 9def0186be upgraded Catch to v1.3.1 2015-12-20 15:42:01 +01:00
Niels 457bfc2401 work on #144 2015-12-20 15:30:07 +01:00
Niels 1adb9d62dd fixed #156 2015-12-17 16:52:38 +01:00
Niels ac4d4a0f66 fixed compilation error and fixed shadow warnings 2015-12-17 16:22:15 +01:00
Niels 07033f67a5 some cleanup and more documentation 2015-12-17 15:49:33 +01:00
Niels fb972e845b show reference to source code in documentation 2015-12-16 12:10:12 +01:00
Niels 6ac89df54d fix for #127 2015-12-16 12:09:59 +01:00
Niels a615598b14 cleanup documentation; started added versions 2015-12-15 19:42:32 +01:00
Niels 1df5d726d9 undid the fix for #136 2015-12-15 18:34:07 +01:00
Niels cd04a7d3e9 fix for #133
added value() function to get object value at given key or a default
value if key does not exist
2015-12-15 08:38:54 +01:00
Niels 2ba901bbf6 cleanup 2015-12-14 21:23:21 +01:00
Niels 5bc1b65676 clean up (for #154) 2015-12-14 16:58:49 +01:00
Niels 258f04c561 fixed #154 (no more warnings for incomplete switches) 2015-12-14 16:32:37 +01:00
Niels a70a7a8001 fixed #135: operator[] now only works on nonconst JSON objects 2015-12-13 11:26:55 +01:00
Niels c767f464bb dropped GCC 4.8 support (due to #110) 2015-12-08 18:12:34 +01:00
Niels 9da8770f3a ignore UTF-8 byte order mark (fixes #152) 2015-12-07 22:27:53 +01:00
Niels e0d334c4f1 added a comment (see #109) 2015-12-07 21:53:32 +01:00
Niels d6771ac79d corrected a username 2015-12-07 21:50:27 +01:00
Niels d9432aa168 Merge pull request #124 from emvivre/master
remove invalid parameter '-stdlib=libc++' in CMakeLists.txt
2015-12-07 21:11:58 +01:00
Niels 22bc022745 added change from #140 2015-12-07 21:05:21 +01:00
Niels 72476b4226 cleanup after #153 2015-12-07 20:38:16 +01:00
Niels f36f316fc7 Merge pull request #153 from whackashoe/remove_sprintf
Replace sprintf with hex function, this fixes #149
2015-12-07 20:35:43 +01:00
Niels 6f8e36ac3d fixes #136 2015-12-06 17:33:52 +01:00
Jett 14d8a91f73 Replace sprintf with hex function, this fixes #149 2015-11-19 00:30:00 -06:00
Niels c013223276 Merge pull request #146 from robertmrk/surrogate-pair-parsing-fix
Fix character skipping after a surrogate pair
2015-11-14 08:22:04 +01:00
Robert Marki ec7a1d8347 Fix character skipping after a surrogate pair
In a string the first character following a surrogate pair is skipped by the
lexer, but the rest of the string is parsed as usual.
2015-11-13 13:13:46 +01:00
Niels 3948630374 Merge pull request #130 from dariomt/patch-1
removed stream operator for iterator, resolution for #125
2015-10-23 18:42:10 +02:00
Niels 8f379ef3eb Merge pull request #137 from dariomt/patch-3
Detect correctly pointer-to-const
2015-10-20 22:31:15 +02:00
dariomt 652e1caa76 Apply same change to the re2c file 2015-10-19 12:34:10 +02:00
dariomt 8162a6e3a3 Apply same change to the re2c file 2015-10-19 12:26:38 +02:00
Niels 746c1a7142 cleanup 2015-10-17 12:51:59 +02:00
Niels 73632377bf Merge pull request #131 from dariomt/patch-2
disabled "CopyAssignable" test for MSVC in Debug mode, see #125
2015-10-17 12:41:20 +02:00
dariomt 04cc7d5a05 doh! disable test correctly only for MSVC 2015-10-16 16:36:34 +02:00
dariomt b342e1207c Detect correctly pointer-to-const
The intention of the current code is to detect a pointer-to-const but instead it is detecting a const-pointer. See #134
2015-10-16 11:11:16 +02:00
dariomt 9d45aafc2c disabled "CopyAssignable" test for MSVC in Debug mode, see #125
STL iterators used by json::iterator don't pass this test in Debug mode.
The test does pass in Release mode, so I felt the best thing to do was selectively disable that test.
2015-10-07 18:31:08 +02:00
dariomt 55cbd903e8 removed stream operator for iterator, resolution for #125
It doesn't really make sense to stream an iterator.
Besides, this was causing trouble in MSVC in Debug mode (see #125)
2015-10-07 17:50:53 +02:00
Niels 57de1d602e Cleanup 2015-10-03 13:16:59 +02:00
Niels 2550d29ded Merge pull request #122 from d-frey/patch-1
exception-safe object creation, fixes #118
2015-10-03 12:29:26 +02:00
Niels 589dc2180a Merge pull request #120 from silverweed/patch-1
Overload parse() to accept an rvalue reference
2015-10-03 10:43:16 +02:00
Niels 4eac295211 Merge pull request #115 from whoshuu/patch-1
Use the right variable name in doc string
2015-10-03 10:41:26 +02:00
Niels b3ff862afc Merge pull request #121 from ColinH/master
Fix small oversight.
2015-10-03 10:39:14 +02:00
Niels 83d068c32c Merge pull request #126 from d-frey/patch-2
Remove superfluous inefficiency
2015-10-03 10:38:18 +02:00
Niels 99261bf39c Merge pull request #129 from dariomt/master
fixed typos in comments for examples
2015-10-03 10:36:35 +02:00
Dario Menendez 260745810d fixed typos in comments for examples 2015-10-02 15:57:40 +02:00
Daniel Frey 1c43789682 Remove superfluous inefficiency 2015-09-25 20:08:35 +02:00
emvivre 4f27004dd5 remove invalid parameter '-stdlib=libc++' in CMakeLists.txt 2015-09-22 16:57:18 +02:00
Daniel Frey f7fb405564 exception-safe object creation, fixes #118 2015-09-20 20:06:33 +02:00
Huu Nguyen 2d7f1542b1 Use the right variable name in doc string 2015-09-20 07:27:34 -07:00
silverweed 8fdd20cdda Overload parse() to accept an rvalue reference 2015-09-20 16:15:55 +02:00
Colin Hirsch c6c37d00d1 Fix small oversight. 2015-09-20 15:04:51 +02:00
Niels 0a81353989 reverted changes 2015-08-22 10:47:14 +02:00
Niels b9592bd2d6 more compilers 2015-08-22 10:43:04 +02:00
Niels 067e33a7ed removed failing compilers 2015-08-21 19:12:06 +02:00
Niels bb0d01e597 better compiler matrix 2015-08-21 19:05:47 +02:00
Niels 941c84e17d debugging 2015-08-14 15:30:06 +02:00
Niels 3c8c2766c1 debugging 2015-08-14 15:20:50 +02:00
Niels 23f70b47ad Appveyor fix 2015-08-14 15:09:16 +02:00
Niels bd5d96c456 minor change 2015-08-14 14:56:58 +02:00
Niels b58a93b8dd merged #111 2015-08-14 14:45:13 +02:00
Niels 6f2da1a39a try to avoid MSVC bug (https://connect.microsoft.com/VisualStudio/feedback/details/797682/c-decltype-of-class-member-access-incompletely-implemented) 2015-08-13 10:24:28 +02:00
Niels fadccc34eb fixed iterator_wrapper 2015-08-13 10:08:55 +02:00
Niels 66ec58639b removed failing tests 2015-08-06 23:02:52 +02:00
Niels 2707733920 fixed off-by-one error 2015-08-06 22:53:16 +02:00
Niels b0eb34394c added test cases for #83 2015-08-06 22:36:08 +02:00
Niels 11ae6da6d9 reverted “fix” for issue #107 2015-08-06 22:35:56 +02:00
Niels b431203fe8 fixed travis script 2015-08-06 21:33:24 +02:00
Niels 2c3259320d addressed locale-issues #107 2015-08-04 18:12:11 +02:00
Niels c910853304 fixed build 2015-08-02 21:49:42 +02:00
Niels b00e627c30 fixed build 2015-08-02 21:47:11 +02:00
Niels 9355dce063 fixed build 2015-08-02 21:40:25 +02:00
Niels e64dc532ab fixed build 2015-08-02 21:35:07 +02:00
Niels b5a05e1121 add a test for the iterator_wrapper 2015-08-02 21:27:02 +02:00
Niels c974e32677 fixed the build 2015-07-30 23:02:55 +02:00
Niels 8eb32084b4 code for #83 (no tests yet) 2015-07-30 21:32:18 +02:00
28 changed files with 6184 additions and 2601 deletions
+31 -28
View File
@@ -2,31 +2,34 @@ language: cpp
sudo: false
compiler:
- gcc
# from http://stackoverflow.com/a/32127147/266378
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:
- COMPILER=g++-4.9
- COMPILER=g++-5
- COMPILER=clang-3.6
- os: linux
compiler: gcc
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5', 'valgrind']
env: COMPILER=g++-5
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise
- llvm-toolchain-precise-3.6
- llvm-toolchain-precise-3.7
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
- 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
script:
- make CXX=$COMPILER CXXFLAGS="-lstdc++"
@@ -34,8 +37,8 @@ script:
- valgrind --error-exitcode=1 --leak-check=full ./json_unit
after_success:
- if [ "$COMPILER" = "g++-4.9" ]; make clean
- if [ "$COMPILER" = "g++-4.9" ]; touch src/json.hpp
- if [ "$COMPILER" = "g++-4.9" ]; make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER
- if [ "$COMPILER" = "g++-4.9" ]; ./json_unit "*"
- 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 make clean ; fi
- if [ "$COMPILER" = "g++-4.9" ]; then touch src/json.hpp ; fi
- 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" ]; then ./json_unit "*" ; fi
- 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
View File
@@ -16,7 +16,7 @@ if(MSVC)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
else(MSVC)
set(CMAKE_CXX_FLAGS
"-std=c++11 -stdlib=libc++"
"-std=c++11"
)
endif(MSVC)
+2
View File
@@ -1,3 +1,5 @@
.PHONY: pretty clean
# used programs
RE2C = re2c
SED = sed
+18 -5
View File
@@ -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:
- GCC 4.8 - 5.2
- Clang 3.4 - 3.7
- Microsoft Visual C++ 14.0 RC
- GCC 4.9 - 6.0 (and possibly later)
- Clang 3.4 - 3.8 (and possibly later)
- Microsoft Visual C++ 14.0 RC (and possibly later)
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
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
// deserialize from standard input
json j;
j << std::cin;
std::cin >> j;
// serialize to standard output
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.
- [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.
- [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!
@@ -385,7 +398,7 @@ $ make
$ ./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).
+2 -1
View File
@@ -1,5 +1,5 @@
version: '{build}'
os: Visual Studio 2015 RC
os: Visual Studio 2015
init: []
install: []
build_script:
@@ -7,4 +7,5 @@ build_script:
- cmake . -G "Visual Studio 14 2015"
- cmake --build . --config Release
test_script:
- Release\json_unit.exe
- Release\json_unit.exe "*"
+1 -1
View File
@@ -121,7 +121,7 @@ USE_MDFILE_AS_MAINPAGE =
#---------------------------------------------------------------------------
# Configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = NO
SOURCE_BROWSER = YES
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = NO
+2 -2
View File
@@ -26,8 +26,8 @@ int main()
{
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
View File
@@ -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 -1
View File
@@ -1,3 +1,3 @@
"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
+2 -2
View File
@@ -21,8 +21,8 @@ int main()
{
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
View File
@@ -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 -1
View File
@@ -1,3 +1,3 @@
"third"
["first","second","third","fourth"]
out of range
out of range: array index 5 is out of range
+29
View File
@@ -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";
}
+1
View File
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/pehnjdIduvv90qfX"><b>online</b></a>
+1
View File
@@ -0,0 +1 @@
1 42.23 oops false
+1 -1
View File
@@ -4,7 +4,7 @@ using namespace nlohmann;
int main()
{
// create a JSON boolean
// create a JSON number
json value = 17;
// explicitly getting pointers
+1 -1
View File
@@ -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>
+1 -1
View File
@@ -4,7 +4,7 @@ using namespace nlohmann;
int main()
{
// create a JSON boolean
// create a JSON number
json value = 17;
// explicitly getting pointers
+1 -1
View File
@@ -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>
+2 -2
View File
@@ -4,13 +4,13 @@ using namespace nlohmann;
int main()
{
// create JSON arrays
// create JSON objects
json j_no_init_list = json::object();
json j_empty_init_list = json::object({});
json j_list_of_pairs = json::object({ {"one", 1}, {"two", 2} });
//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_empty_init_list << '\n';
std::cout << j_list_of_pairs << '\n';
+1 -1
View File
@@ -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()
{
// create a JSON object
json object =
const json object =
{
{"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
View File
File diff suppressed because it is too large Load Diff
+1348 -700
View File
File diff suppressed because it is too large Load Diff
+1716 -929
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -0,0 +1,3 @@
{
"foo": true
}
+1444 -24
View File
File diff suppressed because it is too large Load Diff