Compare commits

..

182 Commits

Author SHA1 Message Date
e22d4bf31f Set version to 6.17.3 2021-02-15 09:53:10 +01:00
21f7b90f03 PlatformIO: set framework compatibility to * (closes #1490) 2021-02-15 09:49:56 +01:00
769e8440f5 CI: skip Particle job for Pull Requests 2021-02-05 13:00:56 +01:00
33de2b6cf3 Added GitHub sponsors 2021-02-05 12:03:50 +01:00
3975b07371 Moved CI from Travis to GitHub Actions (fixes #1493) 2021-02-03 21:33:18 +01:00
abd64102aa Fixed compilation error on Clang 10 2021-02-03 12:56:26 +01:00
d2174d1580 Fixed compilation error when isdigit() is a macro (fixes #1487) 2021-02-02 10:08:10 +01:00
c72eccdd35 Added missing calls to client.stop() in JsonHttpClient.ino (fixes #1485) 2021-02-01 09:16:23 +01:00
ab902128dc Upgrade to Lock Threads 2 2021-01-31 11:00:05 +01:00
c70a491f59 Made JsonDocument's destructor protected (fixes #1480) 2021-01-27 10:00:10 +01:00
322d13de0d Examples: add a note about performance issues with streams (#1476) 2021-01-25 09:26:29 +01:00
97b7161d78 Update copyright notice for 2021 2021-01-25 09:14:15 +01:00
1360b6a396 Set version to 6.17.2 2020-11-14 10:38:21 +01:00
16e51b83ab Changed the default value of ARDUINOJSON_ENABLE_PROGMEM (fixes #1433)
It now checks that the pgm_read_XXX macros are defined before enabling PROGMEM.
2020-11-10 14:58:31 +01:00
aa7cc5351c Travis: added smoke test for Particle Argon 2020-11-10 14:46:45 +01:00
30da920135 Fixed invalid conversion in operator|(Variant, char*) (fixes #1432) 2020-11-09 09:21:19 +01:00
bcdf5b7e52 Set version to 6.17.1 2020-11-07 10:11:41 +01:00
c711fe592d Allowed more than 32767 values in non-embedded mode (fixes #1414) 2020-10-28 09:59:40 +01:00
9d5c1b3742 Added an assert to detect too large variants (issue #1414) 2020-10-24 09:39:03 +02:00
6b26cd0977 Add JsonDocument to keywords.txt
see #1413
2020-10-24 09:37:16 +02:00
10ec0f21b0 Fixed operator|(MemberProxy, JsonObject) (fixes #1415) 2020-10-23 10:48:33 +02:00
ff66182dc6 Gathered the tests of MemberProxy in one file 2020-10-22 09:37:05 +02:00
d02ce2f1bb Gathered the tests of ElementProxy in one file 2020-10-22 09:37:05 +02:00
2664a2d0da Fixed error "ambiguous overload for operator|" (fixes #1411) 2020-10-22 09:30:31 +02:00
1f7350658e Set version to 6.17.0 2020-10-19 11:35:09 +02:00
41132b701b Fixed error "no matching function for pgm_read<double>()" on AVR 2020-10-17 14:02:26 +02:00
712005219c Added filtering for MessagePack (closes #1298, closes #1394) 2020-10-13 09:40:39 +02:00
0bd17aff8a Coverage: use -O0 instead of -Og 2020-10-11 15:10:52 +02:00
f3f44d7812 Renamed StdStringAdapter to StlStringAdapter (internal use only) 2020-10-01 10:01:33 +02:00
8385d5fa3a Added wildcard key (*) for filters (closes #1309) 2020-09-28 21:11:38 +02:00
726f8be341 Added operator|(JsonVariantConst, JsonVariantConst) 2020-09-26 14:48:17 +02:00
fee029b86e Moved float tables to PROGMEM 2020-09-19 16:12:49 +02:00
c3504ddf0a Added tests for DeserializationError::f_str() 2020-09-18 19:06:21 +02:00
6a878ee444 Fixed error "No such file or directory WString.h" (fixes #1381) 2020-09-16 10:29:20 +02:00
c4ec2ba88f Added DeserializationError::f_str() (issue #846) 2020-09-14 18:40:00 +02:00
c907ca6e5d Added DeserializationError::EmptyInput 2020-09-13 10:27:29 +02:00
8993a093e9 Travis: run sanitizer on recent GCC version to avoid false positives 2020-09-13 10:25:34 +02:00
d04669d0cc Fixed result of JsonVariant::set((char*)0) (fixes #1368) 2020-09-05 17:33:47 +02:00
05fc136915 Disabled memory sanitizer with clang 6 2020-09-05 13:44:40 +02:00
8d37939086 Added JsonDocument::overflowed() (closes #1358) 2020-09-05 13:44:40 +02:00
6d2ad4539f Simplified the implementation of parseNumber() 2020-09-04 09:23:40 +02:00
5ab53f42b2 Added a return value to visitors 2020-08-29 18:40:27 +02:00
f448e805e9 Removed dead code 2020-08-25 14:36:14 +02:00
67aa8efd5a Added a build failure when nullptr is defined as a macro (closes #1355) 2020-08-23 09:31:40 +02:00
61a5273aea Set version to 6.16.1 2020-08-04 10:33:38 +02:00
35a39b8d8f Fixed deserializeJson() that stopped reading after {} (fixes #1335) 2020-08-04 09:52:42 +02:00
96b6571352 Fixed use-of-uninitialized-value in encodeCodepoint() 2020-08-03 13:44:45 +02:00
74e7dd053f Added memory sanitizer to fuzzers 2020-08-03 13:44:45 +02:00
1f8636d762 Fixed build-arduino-package.sh to ignore .vs/ 2020-08-01 15:35:04 +02:00
e4cfa701d8 Fixed publish.sh to commit CMakeLists.txt 2020-08-01 15:34:27 +02:00
b85181a6db Set version to 6.16.0 2020-08-01 15:17:39 +02:00
6841b80466 Added JsonString::operator!= 2020-07-31 14:02:20 +02:00
298864bafe Set ARDUINOJSON_DECODE_UNICODE to 1 by default 2020-07-30 09:49:09 +02:00
4d7f03836c Added a test that removes an element during iteration (#1332) 2020-07-30 09:20:31 +02:00
c63eb80b95 Shortened the name of the private namespace using hexadecimal digits 2020-07-30 09:18:08 +02:00
0c0bf80074 Suppress IAR compiler warning. 2020-07-28 10:12:41 +02:00
144ff3b06e Updated the change log. Closes #1210 and closes #1314. 2020-07-26 16:09:03 +02:00
d6c50c3596 Reduced stack usage when compiled with -Og (issue #1210)
This saves 128 bytes on ESP8266
2020-07-26 14:51:58 +02:00
51b177ce47 Reduced stack usage when compiled with -Og (issue #1210)
This saves 112 bytes on ESP8266
2020-07-26 12:58:12 +02:00
824b7a25ca Reduced stack usage when compiled with -Og (issue #1210)
This saves 96 bytes on ESP8266
2020-07-26 12:25:13 +02:00
2223d40640 Reduced stack usage when compiler aggressively inlines deserializeJson()
This saves 64 bytes on the recursive part.
2020-07-26 12:25:13 +02:00
4df29fbac1 Fixed "linked" strings incorrectly marked as "owned" (fixes #1318) 2020-07-24 22:25:56 +02:00
6dc36125c2 Added ElementProxy::getOrAddElement() (fixes #1311) 2020-07-23 10:58:47 +02:00
40085609e2 Fixed copyArray() not working with MemberProxy and ElementProxy 2020-07-22 21:08:18 +02:00
ebb6d80092 Fixed copyArray() not working with String 2020-07-22 20:02:33 +02:00
764ff2cd53 Added string deduplication (closes #1303) 2020-07-21 20:15:31 +02:00
8ef226bcb8 Travis: Added Clang 9. Removed Xcode 7.3 2020-07-15 15:27:39 +02:00
63606c0985 Added json_fuzzer and msgpack_fuzzer in test suite 2020-07-15 12:50:00 +02:00
1600d39693 Refactored StringBuilder into StringStorage 2020-07-11 17:51:45 +02:00
04c59985a1 Inverted dependency between MemoryPool and string adapters.
Inserted a null after each raw string in the pool.
2020-07-08 09:38:27 +02:00
7e58347fbe Added comparisons between JsonVariants 2020-07-02 15:28:34 +02:00
0e794a28a1 Simplified implementation of comparison operators 2020-06-13 15:42:04 +02:00
6fb52c3638 Set version to 6.15.2 2020-05-15 09:26:25 +02:00
b72ef09451 Fixed publish script 2020-05-15 09:26:06 +02:00
f7de027617 Break build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0 2020-05-14 10:25:10 +02:00
bc4c2dde33 Moved failing builds to a dedicated folder 2020-05-12 18:11:55 +02:00
95f05dad66 Added JsonVariant as an input type for deserializeXxx() 2020-05-05 13:16:32 +02:00
3bb0a7aa8e Added support for enums in as<T>() and is<T>() (fixes #1256) 2020-05-04 11:13:06 +02:00
dcf7eeef28 CMake: used link_libraries() instead of target_link_libraries() 2020-05-03 10:25:38 +02:00
3b923b6e4e Added support for JsonDocument to copyArray() (issue #1255) 2020-05-02 10:00:08 +02:00
8050f7404b CMake: gathered all build flags in a dedicated file 2020-04-28 16:02:59 +02:00
959b1d9e4c Fixed error C2766 with flag /Zc:__cplusplus on VS2017+ (fixes #1250) 2020-04-28 16:02:38 +02:00
daa279d57b CMake: made project arch-independent 2020-04-11 18:49:28 +02:00
ae9b7926a2 CMake: don't build tests when imported in another project 2020-04-11 18:49:28 +02:00
1f7a5e6943 Fixed links in README 2020-04-11 11:53:08 +02:00
9e354803de Changed publish.sh to update the CMake project version 2020-04-09 21:28:48 +02:00
3ea5eb3f3a Set version to 6.15.1 2020-04-08 18:23:27 +02:00
ec43bf4fe9 Simplified the implementation of implicit casts 2020-04-08 18:18:18 +02:00
2097ffaabf Updated README 2020-04-08 11:16:22 +02:00
67e78f0751 Disabled alignment on AVR (fixes #1231) 2020-04-08 11:16:22 +02:00
1791dccbf2 Added CMake "install" target (closes #1209) 2020-04-07 21:43:10 +02:00
40d1cfe7af Fixed "pointless integer comparison" warning on IAR (issue #1233) 2020-04-06 18:20:12 +02:00
4627f851ca Fixed "statement is unreachable" warning on IAR (issue #1233) 2020-04-06 18:19:32 +02:00
fc9e609ab5 Fixed "maybe-uninitialized" warning (fixes #1217) 2020-03-25 08:37:57 +01:00
8b3d861a9d Updated README 2020-03-23 13:39:58 +01:00
9ef864b27c Fixed markup in changelog 2020-03-23 11:03:30 +01:00
275b80a462 Updated library description 2020-03-23 11:02:58 +01:00
763be4f266 Set version to 6.15.0 2020-03-22 21:02:38 +01:00
5b812522fa Enabled debug mode when PlatformIO builds in debug 2020-03-20 20:58:08 +01:00
9cb0ddb5e7 Removed the copy-constructor of JsonDocument (issue #1189) 2020-03-05 13:46:45 +01:00
735bea1f47 Added StaticJsonDocument::garbageCollect() 2020-03-02 14:50:16 +01:00
0853b04589 Changed BasicJsonDocument's copy-constructor to copy the capacity 2020-03-02 12:39:29 +01:00
c1b3705df1 Added BasicJsonDocument::garbageCollect() (issue #1195) 2020-03-01 18:01:55 +01:00
2540b4e01b Added move-constructor and move-assignment to BasicJsonDocument 2020-03-01 17:24:29 +01:00
2641697e0b Fixed incorrect string comparison on some platforms (fixes #1198) 2020-02-27 11:44:09 +01:00
2996503b27 Fixed enums serialized as booleans (fixes #1197) 2020-02-26 16:16:20 +01:00
0214c9bcad Improved coverage of JsonObject 2020-02-23 13:03:14 +01:00
a471aed6db Improved coverage of JsonObject 2020-02-22 14:17:10 +01:00
af0edecddb Fixed MemberProxy::set(char[]) not duplicating the string (fixes #1191) 2020-02-22 12:06:39 +01:00
300323cfd7 Improved coverage of JsonArray 2020-02-20 09:18:10 +01:00
d8724e0a0b Changed the array subscript to automatically add missing elements 2020-02-20 08:59:25 +01:00
0001dabfd1 Improved coverage of MemoryPool 2020-02-19 17:27:04 +01:00
ad78001241 Removed useless null checks 2020-02-19 17:22:23 +01:00
5a837a591e Improved coverage of MsgPackDeserializer 2020-02-19 17:14:40 +01:00
fd79d23910 Updated copyright year 2020-02-19 16:07:34 +01:00
1902c0ec93 Improved coverage of JsonDeserializer 2020-02-19 10:31:56 +01:00
85499be855 Added tests for FlashStringAdapter 2020-02-16 17:56:47 +01:00
e6ddfc7afb Fixed static JsonString not being saved by reference 2020-02-16 17:34:04 +01:00
58298ec5ba Extracted storage_policy to improve coverage in string adapters 2020-02-16 17:34:04 +01:00
0814fc185f Added a line-break after each "if" to get more accurate coverage report 2020-02-16 15:05:23 +01:00
8f8c82d400 Reduced code size 2020-02-13 17:05:08 +01:00
372b7d3d9d Exposed JsonPairConst 2020-02-13 16:58:23 +01:00
fbffadb2cf Moved nesting decrement logic to class NestingLimit 2020-02-13 16:54:18 +01:00
6e52f242b2 Extracted the class Latch
also fixed a buffer overrun and reduced the code size
2020-02-13 14:53:54 +01:00
d2a67f362f Fixed "deprecated-copy" warning on GCC 9 (fixes #1184) 2020-02-13 11:07:40 +01:00
66b12da4e7 Added DeserializationOption::Filter (closes #959) 2020-02-12 17:22:42 +01:00
42b0d6a83d Set version to 6.14.1 2020-01-27 15:05:36 +01:00
94b1c75fd2 Added getElement() and getMember() to JsonVariantConst 2020-01-27 12:35:32 +01:00
b04b549b34 Delete .bak file produced during publish 2020-01-27 12:10:11 +01:00
09d4b2cd38 Fixed regression in UTF16 decoding (fixes #1173) 2020-01-27 12:10:10 +01:00
ddfe7d8b91 Set version to 6.14.0 2020-01-16 20:48:03 +01:00
4a657ca87f Update the features section of the README page 2020-01-16 20:46:25 +01:00
1e3d478998 Improved speed of serializeXxx() when writing to a String 2020-01-14 14:50:44 +01:00
3aebef6d0a Fixed value returned by serializeXxx() when writing to a String 2020-01-14 11:22:44 +01:00
25879466da Fixed variant.is<nullptr_t>() 2020-01-13 20:47:43 +01:00
27ec1afb7a Configure the "lock-threads" app 2020-01-13 18:23:30 +01:00
06a0d1a872 Added measureJson, measureJsonPretty, and measureMsgPack to keywords 2020-01-13 18:20:05 +01:00
04fe7e1a27 Added ARDUINOJSON_ENABLE_COMMENTS to enable support for comments 2020-01-13 18:16:02 +01:00
f9cfea244a Updated copyright notice 2020-01-09 15:48:38 +01:00
5ec062cc71 Reduced Unicode conversion code size (-122 bytes on AVR) 2020-01-09 15:39:45 +01:00
91b808381e Improved decoding of UTF-16 surrogate pairs (closes #1157) 2020-01-08 09:55:43 +01:00
8550418875 Auto enable std::string and stream on modern compilers (closes #1156) 2020-01-04 15:05:20 +01:00
00c391320c Added support for CMake's unity builds 2019-12-24 16:42:34 +01:00
9723682d20 AppVeyor: added Visual Studio 2019 2019-12-24 16:10:11 +01:00
8bf6f6e09f Added support uint8_t for serializeMsgPack() (closes #1142) 2019-12-13 14:15:30 +01:00
062c1c13b5 Added BasicJsonDocument::shrinkToFit() 2019-11-07 15:40:20 +01:00
1b8107094f Set version to 6.13.0 2019-11-01 10:32:45 +01:00
8721ac88b1 Reorganized writer classes 2019-10-31 19:27:23 +01:00
6da6f921cd Fixed dangling reference in MemberProxy and ElementProxy (fixes #1120) 2019-10-30 19:09:21 +01:00
ef63757b1a Fixed deserializer that stopped reading at the first 0xFF (closes #1118) 2019-10-29 14:17:11 +01:00
3a169df0a5 Added support for custom reader classes 2019-10-25 11:39:04 +02:00
d4f819f1f0 Added detection of Atmel AVR8/GNU C Compiler (fixes #1112) 2019-10-18 22:10:35 +02:00
16fe3c0acc Improved deserializeMsgPack() speed by reading several bytes at once 2019-10-14 12:02:26 +02:00
fd8f4eb3a6 Moved msgpack.org.md to github.com/bblanchon/ArduinoJson-msgpack.org 2019-10-11 09:07:25 +02:00
b261eca865 esp-idf make system 2019-10-07 09:00:31 +02:00
a37480eec9 Fixed deserializeJson() when input contains duplicate keys (fixes #1095) 2019-09-27 10:07:29 +02:00
713aaa3d68 Added msgpack.org.md
https://github.com/msgpack/website/blob/master/README.md#how-to-list-up-your-project-on-msgpackorg
2019-09-26 09:52:50 +02:00
7d1d0c4e67 Added conversion from JsonArray/JsonObject to bool 2019-09-24 09:38:00 +02:00
4ad05dbaef Replaced GitHub stars badge 2019-09-19 09:28:57 +02:00
38371aae62 Added OSS-Fuzz badge 2019-09-19 09:28:49 +02:00
498a2e4c1e Added support for custom writer classes (closes #1088) 2019-09-13 14:10:21 +02:00
2078871f36 Added missing #include <ArduinoJson/Namespace.hpp> 2019-09-13 12:09:07 +02:00
140525b7a0 Fix deployment scripts 2019-09-05 09:36:18 +02:00
1a81d46a97 Set version to 6.12.0 2019-09-05 09:31:06 +02:00
4c4c4688a9 Fix src/ path in Makefile 2019-09-04 09:13:09 +02:00
b47ac27ac6 Moved ancillary files to extras/ (fixes #1011) 2019-09-03 15:11:05 +02:00
ed18e77655 Changed as<bool>() to return true for any non-null value (closes #1005) 2019-08-29 08:56:34 +02:00
fcbec6eb6d Use absolute instead of relative includes (fixes #1072) 2019-08-26 11:57:57 +02:00
f5c25823bc Set version to 6.11.5 2019-08-23 08:40:10 +02:00
f00dfd7bfe Added fallbacks strlen_P, strncmp_P, strcmp_P and memcpy_P (fixes #1073) 2019-08-21 15:25:54 +02:00
dcca4214f5 Set version to 6.11.4 2019-08-12 15:10:56 +02:00
1e9cc285bb Added support for basic_string<char, traits, allocator> (closes #1045) 2019-08-12 14:21:45 +02:00
b9c4a0c5f6 Include Arduino.h if ARDUINO is defined (closes #1071) 2019-08-11 13:04:12 +02:00
0d339300f9 Added tests for Flash strings (closes #1070) 2019-08-11 11:39:21 +02:00
63d7d87080 Fixed example JsonConfigFile.ino for ESP8266 2019-08-10 14:17:23 +02:00
2ee655f9ba Fix clang installation on Travis 2019-08-10 12:22:17 +02:00
61a4195ed4 Added measureJson() to the ArduinoJson namespace (fixes #1069) 2019-08-10 11:15:11 +02:00
a6f029ded0 Set version to 6.11.3 2019-07-22 08:59:54 +02:00
b54de58e6b Fixed comparison of JsonVariant with mixed strings (closes #1051) 2019-07-19 12:15:16 +02:00
795e37278f Added operators == and != for MemberProxy 2019-07-19 10:27:03 +02:00
7ce1039d7c Added operators == and != for MemberProxy 2019-07-19 10:23:06 +02:00
aba42faf69 Added operators == and != for JsonDocument 2019-07-19 10:23:06 +02:00
458 changed files with 13466 additions and 5687 deletions

View File

@ -3,3 +3,6 @@
BasedOnStyle: Google
Standard: Cpp03
AllowShortFunctionsOnASingleLine: Empty
# Always break after if to get accurate coverage
AllowShortIfStatementsOnASingleLine: false

1
.github/FUNDING.yml vendored
View File

@ -1 +1,2 @@
github: bblanchon
custom: https://arduinojson.org/book/

253
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,253 @@
name: Continuous Integration
on: [push, pull_request]
jobs:
gcc:
name: GCC
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- gcc: '4.4'
- gcc: '4.6'
- gcc: '4.7'
- gcc: '4.8'
- gcc: '4.9'
- gcc: '5'
- gcc: '6'
- gcc: '7'
cxxflags: -fsanitize=leak
- gcc: '8'
cxxflags: -fsanitize=undefined
- gcc: '9'
cxxflags: -fsanitize=address
- gcc: '10'
steps:
- name: Install
run: |
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
sudo apt-get update
sudo apt-get install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }}
if: ${{ matrix.gcc < 7 }}
- name: Checkout
uses: actions/checkout@v2
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Debug .
env:
CC: gcc-${{ matrix.gcc }}
CXX: g++-${{ matrix.gcc }}
CXXFLAGS: ${{ matrix.cxxflags }}
- name: Build
run: cmake --build .
- name: Test
run: ctest --output-on-failure -C Debug .
clang:
name: Clang
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- clang: '3.5'
- clang: '3.6'
- clang: '3.7'
- clang: '3.8'
- clang: '3.9'
- clang: '4.0'
- clang: '5.0'
- clang: '6.0'
- clang: '7'
- clang: '8'
cxxflags: -fsanitize=leak
- clang: '9'
cxxflags: -fsanitize=undefined
- clang: '10'
cxxflags: -fsanitize=address
steps:
- name: Install
run: |
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
sudo apt-get update
sudo apt-get install -y clang-${{ matrix.clang }}
if: ${{ matrix.clang < 8 }}
- name: Checkout
uses: actions/checkout@v2
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Debug .
env:
CC: clang-${{ matrix.clang }}
CXX: clang++-${{ matrix.clang }}
CXXFLAGS: ${{ matrix.cxxflags }}
- name: Build
run: cmake --build .
- name: Test
run: ctest --output-on-failure -C Debug .
xcode:
name: XCode
needs: clang
runs-on: macos-10.15
strategy:
fail-fast: false
matrix:
include:
- xcode: '10.3'
- xcode: '11.7'
- xcode: '12.4'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Select XCode version
run: sudo xcode-select --switch /Applications/Xcode_${{ matrix.xcode }}.app
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Debug .
- name: Build
run: cmake --build .
- name: Test
run: ctest --output-on-failure -C Debug .
# DISABLED: Running on AppVeyor instead because it supports older versions of the compiler
# msvc:
# name: Visual Studio
# strategy:
# fail-fast: false
# matrix:
# include:
# - os: windows-2016
# - os: windows-2019
# runs-on: ${{ matrix.os }}
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - name: Configure
# run: cmake -DCMAKE_BUILD_TYPE=Debug .
# - name: Build
# run: cmake --build .
# - name: Test
# run: ctest --output-on-failure -C Debug .
arduino:
name: Arduino
needs: gcc
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- arduino: '1.6.7'
board: arduino:avr:uno
- arduino: '1.8.2'
board: arduino:samd:mkr1000
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: extras/ci/arduino.sh ${{ matrix.board }}
env:
BOARD: ${{ matrix.board }}
VERSION: ${{ matrix.arduino }}
platformio:
name: PlatformIO
needs: gcc
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- board: uno
- board: esp01
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install PlatformIO
run: pip install platformio
- name: Build
run: extras/ci/platformio.sh ${{ matrix.board }}
particle:
name: Particle
needs: gcc
runs-on: ubuntu-latest
if: github.event_name == 'push'
strategy:
fail-fast: false
matrix:
include:
- board: argon
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Particle CLI
run: sudo npm install -g particle-cli
- name: Login to Particle
run: particle login -t "${{ secrets.PARTICLE_TOKEN }}"
- name: Compile
run: extras/ci/particle.sh ${{ matrix.board }}
arm:
name: GCC for ARM processor
needs: gcc
runs-on: ubuntu-20.04
steps:
- name: Install
run: sudo apt-get install -y g++-arm-linux-gnueabihf
- name: Checkout
uses: actions/checkout@v2
- name: Configure
run: cmake .
env:
CC: arm-linux-gnueabihf-gcc
CXX: arm-linux-gnueabihf-g++
- name: Build
run: cmake --build .
coverage:
needs: gcc
name: Coverage
runs-on: ubuntu-20.04
steps:
- name: Install
run: sudo apt-get install -y lcov ninja-build
- name: Checkout
uses: actions/checkout@v2
- name: Configure
run: cmake -G Ninja -DCOVERAGE=true .
- name: Build
run: ninja
- name: Test
run: ninja test
- name: lcov --capture
run: lcov --capture --no-external --directory . --output-file coverage.info
- name: lcov --remove
run: lcov --remove coverage.info "$(pwd)/extras/*" --output-file coverage_filtered.info
- name: genhtml
run: mkdir coverage && genhtml coverage_filtered.info -o coverage -t ArduinoJson
- name: Upload HTML report
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage
- name: Upload to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage_filtered.info

14
.github/workflows/lock.yml vendored Normal file
View File

@ -0,0 +1,14 @@
name: 'Lock Threads'
on:
schedule:
- cron: '0 0 * * *'
jobs:
lock:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v2
with:
github-token: ${{ github.token }}
issue-lock-inactive-days: 30

10
.gitignore vendored
View File

@ -6,7 +6,11 @@
/sftp-config.json
.tags
.tags_sorted_by_file
/fuzzing/*_fuzzer
/fuzzing/*_fuzzer.options
/fuzzing/*_fuzzer_seed_corpus.zip
/extras/fuzzing/*_fuzzer
/extras/fuzzing/*_fuzzer.options
/extras/fuzzing/*_fuzzer_seed_corpus.zip
.vs/
# Used by CI for Particle
/src/*.ino
/project.properties

View File

@ -1,132 +0,0 @@
sudo: false
language: cpp
matrix:
include:
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.4']
env: SCRIPT=test _CC=gcc-4.4 _CXX=g++-4.4
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.6']
env: SCRIPT=test _CC=gcc-4.6 _CXX=g++-4.6
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.7']
env: SCRIPT=test _CC=gcc-4.7 _CXX=g++-4.7
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.8']
env: SCRIPT=test _CC=gcc-4.8 _CXX=g++-4.8 SANITIZE=address
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.9']
env: SCRIPT=test _CC=gcc-4.9 _CXX=g++-4.9 SANITIZE=leak
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5']
env: SCRIPT=test _CC=gcc-5 _CXX=g++-5 # SANITIZE=undefined
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6']
env: SCRIPT=test _CC=gcc-6 _CXX=g++-6
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-7']
env: SCRIPT=test _CC=gcc-7 _CXX=g++-7
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-8']
env: SCRIPT=test _CC=gcc-8 _CXX=g++-8
- addons:
apt:
packages: ['g++-arm-linux-gnueabihf']
env: SCRIPT=build _CC=arm-linux-gnueabihf-gcc _CXX=arm-linux-gnueabihf-g++
- env: SCRIPT=test _CC=clang _CXX=clang++
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5']
packages: ['clang-3.5']
env: SCRIPT=test _CC=clang-3.5 _CXX=clang++-3.5 SANITIZE=address
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.6']
packages: ['clang-3.6']
env: SCRIPT=test _CC=clang-3.6 _CXX=clang++-3.6 SANITIZE=leak
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.7']
packages: ['clang-3.7']
env: SCRIPT=test _CC=clang-3.7 _CXX=clang++-3.7
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.8']
packages: ['clang-3.8']
env: SCRIPT=test _CC=clang-3.8 _CXX=clang++-3.8 SANITIZE=undefined
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-3.9']
packages: ['clang-3.9']
env: SCRIPT=test _CC=clang-3.9 _CXX=clang++-3.9
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-4.0']
packages: ['clang-4.0']
env: SCRIPT=test _CC=clang-4.0 _CXX=clang++-4.0
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-5.0']
packages: ['clang-5.0']
env: SCRIPT=test _CC=clang-5.0 _CXX=clang++-5.0
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-6.0']
packages: ['clang-6.0']
env: SCRIPT=test _CC=clang-6.0 _CXX=clang++-6.0
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-7']
packages: ['clang-7']
env: SCRIPT=test _CC=clang-7 _CXX=clang++-7
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-8']
packages: ['clang-8']
env: SCRIPT=test _CC=clang-8 _CXX=clang++-8
- env: SCRIPT=coverage
- os: osx
osx_image: xcode7.3
env: SCRIPT=test
- os: osx
osx_image: xcode8.3
env: SCRIPT=test
- os: osx
osx_image: xcode9.4
env: SCRIPT=test
- os: osx
osx_image: xcode10
env: SCRIPT=test SANITIZE=address
- env: SCRIPT=arduino VERSION=1.6.7 BOARD=arduino:avr:uno
- env: SCRIPT=arduino VERSION=1.8.2 BOARD=arduino:samd:mkr1000
- env: SCRIPT=platformio BOARD=uno
- env: SCRIPT=platformio BOARD=esp01
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-6.0']
packages: ['clang-6.0','llvm-6.0']
env: SCRIPT=fuzz CLANG=6.0
cache:
directories:
- "~/.platformio"
- "fuzzing/json_corpus"
- "fuzzing/msgpack_corpus"
script: scripts/travis/$SCRIPT.sh

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include "src/ArduinoJson.h"

View File

@ -1,6 +1,209 @@
ArduinoJson: change log
=======================
v6.17.3 (2021-02-15)
-------
* Made `JsonDocument`'s destructor protected (issue #1480)
* Added missing calls to `client.stop()` in `JsonHttpClient.ino` (issue #1485)
* Fixed error `expected ')' before 'char'` when `isdigit()` is a macro (issue #1487)
* Fixed error `definition of implicit copy constructor is deprecated` on Clang 10
* PlatformIO: set framework compatibility to `*` (PR #1490 by @maxgerhardt)
v6.17.2 (2020-11-14)
-------
* Fixed invalid conversion error in `operator|(JsonVariant, char*)` (issue #1432)
* Changed the default value of `ARDUINOJSON_ENABLE_PROGMEM` (issue #1433).
It now checks that the `pgm_read_XXX` macros are defined before enabling `PROGMEM`.
v6.17.1 (2020-11-07)
-------
* Fixed error `ambiguous overload for 'operator|'` (issue #1411)
* Fixed `operator|(MemberProxy, JsonObject)` (issue #1415)
* Allowed more than 32767 values in non-embedded mode (issue #1414)
v6.17.0 (2020-10-19)
-------
* Added a build failure when nullptr is defined as a macro (issue #1355)
* Added `JsonDocument::overflowed()` which tells if the memory pool was too small (issue #1358)
* Added `DeserializationError::EmptyInput` which tells if the input was empty
* Added `DeserializationError::f_str()` which returns a `const __FlashStringHelper*` (issue #846)
* Added `operator|(JsonVariantConst, JsonVariantConst)`
* Added filtering for MessagePack (issue #1298, PR #1394 by Luca Passarella)
* Moved float convertion tables to PROGMEM
* Fixed `JsonVariant::set((char*)0)` which returned false instead of true (issue #1368)
* Fixed error `No such file or directory #include <WString.h>` (issue #1381)
v6.16.1 (2020-08-04)
-------
* Fixed `deserializeJson()` that stopped reading after `{}` (issue #1335)
v6.16.0 (2020-08-01)
-------
* Added comparisons (`>`, `>=`, `==`, `!=`, `<`, and `<=`) between `JsonVariant`s
* Added string deduplication (issue #1303)
* Added `JsonString::operator!=`
* Added wildcard key (`*`) for filters (issue #1309)
* Set `ARDUINOJSON_DECODE_UNICODE` to `1` by default
* Fixed `copyArray()` not working with `String`, `ElementProxy`, and `MemberProxy`
* Fixed error `getOrAddElement is not a member of ElementProxy` (issue #1311)
* Fixed excessive stack usage when compiled with `-Og` (issues #1210 and #1314)
* Fixed `Warning[Pa093]: implicit conversion from floating point to integer` on IAR compiler (PR #1328 by @stawiski)
v6.15.2 (2020-05-15)
-------
* CMake: don't build tests when imported in another project
* CMake: made project arch-independent
* Visual Studio: fixed error C2766 with flag `/Zc:__cplusplus` (issue #1250)
* Added support for `JsonDocument` to `copyArray()` (issue #1255)
* Added support for `enum`s in `as<T>()` and `is<T>()` (issue #1256)
* Added `JsonVariant` as an input type for `deserializeXxx()`
For example, you can do: `deserializeJson(doc2, doc1["payload"])`
* Break the build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0
v6.15.1 (2020-04-08)
-------
* Fixed "maybe-uninitialized" warning (issue #1217)
* Fixed "statement is unreachable" warning on IAR (issue #1233)
* Fixed "pointless integer comparison" warning on IAR (issue #1233)
* Added CMake "install" target (issue #1209)
* Disabled alignment on AVR (issue #1231)
v6.15.0 (2020-03-22)
-------
* Added `DeserializationOption::Filter` (issue #959)
* Added example `JsonFilterExample.ino`
* Changed the array subscript operator to automatically add missing elements
* Fixed "deprecated-copy" warning on GCC 9 (fixes #1184)
* Fixed `MemberProxy::set(char[])` not duplicating the string (issue #1191)
* Fixed enums serialized as booleans (issue #1197)
* Fixed incorrect string comparison on some platforms (issue #1198)
* Added move-constructor and move-assignment to `BasicJsonDocument`
* Added `BasicJsonDocument::garbageCollect()` (issue #1195)
* Added `StaticJsonDocument::garbageCollect()`
* Changed copy-constructor of `BasicJsonDocument` to preserve the capacity of the source.
* Removed copy-constructor of `JsonDocument` (issue #1189)
> ### BREAKING CHANGES
>
> #### Copy-constructor of `BasicJsonDocument`
>
> In previous versions, the copy constructor of `BasicJsonDocument` looked at the source's `memoryUsage()` to choose its capacity.
> Now, the copy constructor of `BasicJsonDocument` uses the same capacity as the source.
>
> Example:
>
> ```c++
> DynamicJsonDocument doc1(64);
> doc1.set(String("example"));
>
> DynamicJsonDocument doc2 = doc1;
> Serial.print(doc2.capacity()); // 8 with ArduinoJson 6.14
> // 64 with ArduinoJson 6.15
> ```
>
> I made this change to get consistent results between copy-constructor and move-constructor, and whether RVO applies or not.
>
> If you use the copy-constructor to optimize your documents, you can use `garbageCollect()` or `shrinkToFit()` instead.
>
> #### Copy-constructor of `JsonDocument`
>
> In previous versions, it was possible to create a function that take a `JsonDocument` by value.
>
> ```c++
> void myFunction(JsonDocument doc) {}
> ```
>
> This function gives the wrong clues because it doesn't receive a copy of the `JsonDocument`, only a sliced version.
> It worked because the copy constructor copied the internal pointers, but it was an accident.
>
> From now, if you need to pass a `JsonDocument` to a function, you must use a reference:
>
> ```c++
> void myFunction(JsonDocument& doc) {}
> ```
v6.14.1 (2020-01-27)
-------
* Fixed regression in UTF16 decoding (issue #1173)
* Fixed `containsKey()` on `JsonVariantConst`
* Added `getElement()` and `getMember()` to `JsonVariantConst`
v6.14.0 (2020-01-16)
-------
* Added `BasicJsonDocument::shrinkToFit()`
* Added support of `uint8_t` for `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` (issue #1142)
* Added `ARDUINOJSON_ENABLE_COMMENTS` to enable support for comments (defaults to 0)
* Auto enable support for `std::string` and `std::stream` on modern compilers (issue #1156)
(No need to define `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_STD_STREAM` anymore)
* Improved decoding of UTF-16 surrogate pairs (PR #1157 by @kaysievers)
(ArduinoJson now produces standard UTF-8 instead of CESU-8)
* Added `measureJson`, `measureJsonPretty`, and `measureMsgPack` to `keywords.txt`
(This file is used for syntax highlighting in the Arduino IDE)
* Fixed `variant.is<nullptr_t>()`
* Fixed value returned by `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String`
* Improved speed of `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String`
> ### BREAKING CHANGES
>
> #### Comments
>
> Support for comments in input is now optional and disabled by default.
>
> If you need support for comments, you must defined `ARDUINOJSON_ENABLE_COMMENTS` to `1`; otherwise, you'll receive `InvalidInput` errors.
>
> ```c++
> #define ARDUINOJSON_ENABLE_COMMENTS 1
> #include <ArduinoJson.h>
> ```
v6.13.0 (2019-11-01)
-------
* Added support for custom writer/reader classes (issue #1088)
* Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant`
* Fixed `deserializeJson()` when input contains duplicate keys (issue #1095)
* Improved `deserializeMsgPack()` speed by reading several bytes at once
* Added detection of Atmel AVR8/GNU C Compiler (issue #1112)
* Fixed deserializer that stopped reading at the first `0xFF` (PR #1118 by @mikee47)
* Fixed dangling reference in copies of `MemberProxy` and `ElementProxy` (issue #1120)
v6.12.0 (2019-09-05)
-------
* Use absolute instead of relative includes (issue #1072)
* Changed `JsonVariant::as<bool>()` to return `true` for any non-null value (issue #1005)
* Moved ancillary files to `extras/` (issue #1011)
v6.11.5 (2019-08-23)
-------
* Added fallback implementations of `strlen_P()`, `strncmp_P()`, `strcmp_P()`, and `memcpy_P()` (issue #1073)
v6.11.4 (2019-08-12)
-------
* Added `measureJson()` to the `ArduinoJson` namespace (PR #1069 by @nomis)
* Added support for `basic_string<char, traits, allocator>` (issue #1045)
* Fixed example `JsonConfigFile.ino` for ESP8266
* Include `Arduino.h` if `ARDUINO` is defined (PR #1071 by @nomis)
v6.11.3 (2019-07-22)
-------
* Added operators `==` and `!=` for `JsonDocument`, `ElementProxy`, and `MemberProxy`
* Fixed comparison of `JsonVariant` when one contains a linked string and the other contains an owned string (issue #1051)
v6.11.2 (2019-07-08)
-------

View File

@ -1,22 +1,19 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# Copyright Benoit Blanchon 2014-2021
# MIT License
cmake_minimum_required(VERSION 3.0)
project(ArduinoJson)
enable_testing()
project(ArduinoJson VERSION 6.17.3)
add_definitions(-DARDUINOJSON_DEBUG)
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options(-g -O0)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()
if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
endif()
add_subdirectory(src)
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
add_subdirectory(third-party/catch)
add_subdirectory(test)
add_subdirectory(fuzzing)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
include(extras/CompileOptions.cmake)
add_subdirectory(extras/tests)
add_subdirectory(extras/fuzzing)
endif()

View File

@ -6,6 +6,5 @@ You can submit changes via GitHub Pull Requests.
Please:
1. Unit test every change in behavior
1. Update the test suite for any change of behavior
2. Use clang-format in "file" mode to format the code
3. Consider using the Continuous Integration (Travis and AppVeyor)

View File

@ -1,7 +1,7 @@
The MIT License (MIT)
---------------------
Copyright © 2014-2019 Benoit BLANCHON
Copyright © 2014-2021 Benoit BLANCHON
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:

150
README.md
View File

@ -2,58 +2,95 @@
---
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.11.2)](https://www.ardu-badge.com/ArduinoJson/6.11.2)
[![Build Status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
[![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=6.x)](https://travis-ci.org/bblanchon/ArduinoJson)
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.17.3)](https://www.ardu-badge.com/ArduinoJson/6.17.3)
[![Continuous Integration](https://github.com/bblanchon/ArduinoJson/workflows/Continuous%20Integration/badge.svg?branch=6.x)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
[![Coverage Status](https://coveralls.io/repos/github/bblanchon/ArduinoJson/badge.svg?branch=6.x)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
[![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson)
[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat)](https://github.com/bblanchon/ArduinoJson/stargazers)
ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
## Features
* JSON decoding (comments are supported)
* JSON encoding (with optional indentation)
* MessagePack
* Elegant API, easy to use
* Fixed memory allocation (zero malloc)
* No data duplication (zero copy)
* Portable (written in C++98, can be used in any C++ project)
* Self-contained (no external dependency)
* Small footprint
* Input and output streams
* [100% code coverage](https://coveralls.io/github/bblanchon/ArduinoJson)
* [Header-only library](https://en.wikipedia.org/wiki/Header-only)
* [MIT License](https://en.wikipedia.org/wiki/MIT_License)
* [Comprehensive documentation](https://arduinojson.org?utm_source=github&utm_medium=readme)
## Compatibility
ArduinoJson works on the following hardware:
* <img src="https://www.arduino.cc/favicon.ico" height="16" width="16"> Arduino boards: [Uno](https://www.arduino.cc/en/Main/ArduinoBoardUno), [Due](https://www.arduino.cc/en/Main/ArduinoBoardDue), [Mini](https://www.arduino.cc/en/Main/ArduinoBoardMini), [Micro](https://www.arduino.cc/en/Main/ArduinoBoardMicro), [Yun](https://www.arduino.cc/en/Main/ArduinoBoardYun)...
* <img src="http://espressif.com/sites/all/themes/espressif/favicon.ico" height="16" width="16"> Espressif chips: [ESP8266](https://en.wikipedia.org/wiki/ESP8266), [ESP32](https://en.wikipedia.org/wiki/ESP32)
* <img src="https://www.wemos.cc/themes/martin-materialize-parallax/assets/favicon.ico" height="16" width="16"> WeMos boards: [D1](https://wiki.wemos.cc/products:d1:d1), [D1 mini](https://wiki.wemos.cc/products:d1:d1_mini), ...
* <img src="http://redbearlab.com/favicon.ico" height="16" width="16"> RedBearLab boards: [BLE Nano](http://redbearlab.com/blenano/), [BLE Mini](http://redbearlab.com/blemini/), [WiFi Micro](https://redbear.cc/product/wifi/wifi-micro.html), [LOLIN32](https://wiki.wemos.cc/products:lolin32:lolin32)...
* <img src="https://www.pjrc.com/favicon.ico" height="16" width="16"> [Teensy](https://www.pjrc.com/teensy/) boards
* <img src="https://software.intel.com/sites/all/themes/zero/favicon.ico" height="16" width="16"> Intel boards: Edison, Galileo...
* <img src="https://www-assets.particle.io/images/favicon.png" height="16" width="16"> Particle boards: [Photon](https://www.particle.io/products/hardware/photon-wifi-dev-kit), [Electron](https://www.particle.io/products/hardware/electron-cellular-dev-kit)...
* <img src="http://www.ti.com/favicon.ico" height="16" width="16"> Texas Instruments boards: [MSP430](http://www.ti.com/microcontrollers/msp430-ultra-low-power-mcus/overview/overview.html)...
ArduinoJson compiles with zero warning on the following compilers, IDEs, and platforms:
* <img src="https://www.arduino.cc/favicon.ico" height="16" width="16"> [Arduino IDE](https://www.arduino.cc/en/Main/Software)
* <img src="http://cdn.platformio.org/favicon.ico" height="16" width="16"> [PlatformIO](http://platformio.org/)
* <img src="http://energia.nu/img/favicon.ico" height="16" width="16"> [Energia](http://energia.nu/)
* <img src="http://www.visualmicro.com/pics/arduino-visual-studio-ld.png" height="16" width="16"> [Visual Micro](http://www.visualmicro.com/)
* <img src="http://www.atmel.com/Images/favicon.ico" height="16" width="16"> [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/)
* <img src="https://www.iar.com/favicon.ico" height="16" width="16"> [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/)
* <img src="http://www.st.com/etc/clientlibs/st-site/media/app/images/favicon.png" height="16" width="16"> [Atollic TrueSTUDIO](https://atollic.com/truestudio/)
* <img src="http://www.keil.com/favicon.ico" height="16" width="16"> [Keil uVision](http://www.keil.com/)
* <img src="http://www.microchip.com/favicon.ico" height="16" width="16"> [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide)
* <img src="https://gcc.gnu.org/favicon.ico" height="16" width="16"> [GCC](https://gcc.gnu.org/)
* <img src="https://clang.llvm.org/favicon.ico" height="16" width="16"> [Clang](https://clang.llvm.org/)
* <img src="https://www.visualstudio.com/favicon.ico" height="16" width="16"> [Visual Studio](https://www.visualstudio.com/)
* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme)
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/?utm_source=github&utm_medium=readme)
* [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme)
* [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/?utm_source=github&utm_medium=readme)
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#filtering)
* Supports single quotes as a string delimiter
* Compatible with [NDJSON](http://ndjson.org/) and [JSON Lines](https://jsonlines.org/)
* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme)
* [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme)
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/?utm_source=github&utm_medium=readme)
* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/?utm_source=github&utm_medium=readme)
* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/?utm_source=github&utm_medium=readme)
* Efficient
* [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme)
* [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme)
* [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme)
* [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/?utm_source=github&utm_medium=readme)
* [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme)
* Deduplicates strings
* Versatile
* [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme)
* Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme)
* Supports Arduino's `Stream` and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme)
* [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme)
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer)
* Portable
* Usable on any C++ project (not limited to Arduino)
* Compatible with C++98
* Zero warnings with `-Wall -Wextra -pedantic` and `/W4`
* [Header-only library](https://en.wikipedia.org/wiki/Header-only)
* Works with virtually any board
* Arduino boards: [Uno](https://amzn.to/38aL2ik), [Due](https://amzn.to/36YkWi2), [Micro](https://amzn.to/35WkdwG), [Nano](https://amzn.to/2QTvwRX), [Mega](https://amzn.to/36XWhuf), [Yun](https://amzn.to/30odURc), [Leonardo](https://amzn.to/36XWjlR)...
* Espressif chips: [ESP8266](https://amzn.to/36YluV8), [ESP32](https://amzn.to/2G4pRCB)
* Lolin (WeMos) boards: [D1 mini](https://amzn.to/2QUpz7q), [D1 Mini Pro](https://amzn.to/36UsGSs)...
* Teensy boards: [4.0](https://amzn.to/30ljXGq), [3.2](https://amzn.to/2FT0EuC), [2.0](https://amzn.to/2QXUMXj)
* Particle boards: [Argon](https://amzn.to/2FQHa9X), [Boron](https://amzn.to/36WgLUd), [Electron](https://amzn.to/30vEc4k), [Photon](https://amzn.to/387F9Cd)...
* Texas Instruments boards: [MSP430](https://amzn.to/30nJWgg)...
* Tested on all major development environments
* [Arduino IDE](https://www.arduino.cc/en/Main/Software)
* [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/)
* [Atollic TrueSTUDIO](https://atollic.com/truestudio/)
* [Energia](http://energia.nu/)
* [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/)
* [Keil uVision](http://www.keil.com/)
* [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide)
* [Particle](https://www.particle.io/)
* [PlatformIO](http://platformio.org/)
* [Sloeber plugin for Eclipse](https://eclipse.baeyens.it/)
* [Visual Micro](http://www.visualmicro.com/)
* [Visual Studio](https://www.visualstudio.com/)
* [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/RlZSKy17DjJ6HcdN)
* [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/?utm_source=github&utm_medium=readme)
* Well designed
* [Elegant API](http://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
* [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
* Self-contained (no external dependency)
* `const` friendly
* [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/?utm_source=github&utm_medium=readme)
* [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming)
* Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/?utm_source=github&utm_medium=readme#integer-overflows)
* Well tested
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
* Continuously tested on
* [Visual Studio 2010, 2012, 2013, 2015, 2017, 2019](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
* [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
* [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
* Well documented
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme)
* [Examples](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
* [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
* [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme)
* [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme)
* [Changelog](changelog.md)
* Vibrant user community
* Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) and [PlatformIO](https://platformio.org/lib/search)
* [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson)
* [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed)
## Quickstart
@ -84,10 +121,8 @@ DynamicJsonDocument doc(1024);
doc["sensor"] = "gps";
doc["time"] = 1351824120;
JsonArray data = doc.createNestedArray("data");
data.add(48.756080);
data.add(2.302038);
doc["data"][0] = 48.756080;
doc["data"][1] = 2.302038;
serializeJson(doc, Serial);
// This prints:
@ -96,18 +131,9 @@ serializeJson(doc, Serial);
See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/?utm_source=github&utm_medium=readme)
## Documentation
The documentation is available on [arduinojson.org](https://arduinojson.org/?utm_source=github&utm_medium=readme), here are some shortcuts:
* The [Examples](https://arduinojson.org/example/?utm_source=github&utm_medium=readme) show how to use the library in various situations.
* The [API Reference](https://arduinojson.org/api/?utm_source=github&utm_medium=readme) contains the description of each class and function.
* The [FAQ](https://arduinojson.org/faq/?utm_source=github&utm_medium=readme) has the answer to virtually every question.
* The [ArduinoJson Assistant](https://arduinojson.org/assistant/?utm_source=github&utm_medium=readme) writes programs for you!
---
## Support the project
Do you like this library? Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)!
What? You don't like it but you *love* it?
We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time!
What? You don't like it but you *love* it?
We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time.

View File

@ -1,6 +1,8 @@
version: 6.11.2.{build}
version: 6.17.3.{build}
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
CMAKE_GENERATOR: Visual Studio 16 2019
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_GENERATOR: Visual Studio 15 2017
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015

1
component.mk Normal file
View File

@ -0,0 +1 @@
COMPONENT_ADD_INCLUDEDIRS := src

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to store your project configuration in a file.
@ -11,6 +11,12 @@
// "port": 2731
// }
//
// To run this program, you need an SD card connected to the SPI bus as follows:
// * MOSI <-> pin 11
// * MISO <-> pin 12
// * CLK <-> pin 13
// * CS <-> pin 4
//
// https://arduinojson.org/v6/example/config/
#include <ArduinoJson.h>
@ -111,7 +117,8 @@ void setup() {
while (!Serial) continue;
// Initialize SD library
while (!SD.begin()) {
const int chipSelect = 4;
while (!SD.begin(chipSelect)) {
Serial.println(F("Failed to initialize SD library"));
delay(1000);
}
@ -133,6 +140,12 @@ void loop() {
// not used in this example
}
// Performance issue?
// ------------------
//
// File is an unbuffered stream, which is not optimal for ArduinoJson.
// See: https://arduinojson.org/v6/how-to/improve-speed/
// See also
// --------
//

View File

@ -0,0 +1,63 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to use DeserializationOpion::Filter
//
// https://arduinojson.org/v6/example/filter/
#include <ArduinoJson.h>
void setup() {
// Initialize serial port
Serial.begin(9600);
while (!Serial) continue;
// The huge input: an extract from OpenWeatherMap response
const __FlashStringHelper* input_json = F(
"{\"cod\":\"200\",\"message\":0,\"list\":[{\"dt\":1581498000,\"main\":{"
"\"temp\":3.23,\"feels_like\":-3.63,\"temp_min\":3.23,\"temp_max\":4.62,"
"\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":"
"58,\"temp_kf\":-1.39},\"weather\":[{\"id\":800,\"main\":\"Clear\","
"\"description\":\"clear "
"sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":0},\"wind\":{\"speed\":6."
"19,\"deg\":266},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 "
"09:00:00\"},{\"dt\":1581508800,\"main\":{\"temp\":6.09,\"feels_like\":-"
"1.07,\"temp_min\":6.09,\"temp_max\":7.13,\"pressure\":1015,\"sea_"
"level\":1015,\"grnd_level\":1011,\"humidity\":48,\"temp_kf\":-1.04},"
"\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear "
"sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":9},\"wind\":{\"speed\":6."
"64,\"deg\":268},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 "
"12:00:00\"}],\"city\":{\"id\":2643743,\"name\":\"London\",\"coord\":{"
"\"lat\":51.5085,\"lon\":-0.1257},\"country\":\"GB\",\"population\":"
"1000000,\"timezone\":0,\"sunrise\":1581492085,\"sunset\":1581527294}}");
// The filter: it contains "true" for each value we want to keep
StaticJsonDocument<200> filter;
filter["list"][0]["dt"] = true;
filter["list"][0]["main"]["temp"] = true;
// Deserialize the document
StaticJsonDocument<400> doc;
deserializeJson(doc, input_json, DeserializationOption::Filter(filter));
// Print the result
serializeJsonPretty(doc, Serial);
}
void loop() {
// not used in this example
}
// See also
// --------
//
// https://arduinojson.org/ contains the documentation for all the functions
// used above. It also includes an FAQ that will help you solve any
// deserialization problem.
//
// The book "Mastering ArduinoJson" contains a tutorial on deserialization.
// It begins with a simple example, like the one above, and then adds more
// features like deserializing directly from a file or an HTTP request.
// Learn more at https://arduinojson.org/book/
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to generate a JSON document with ArduinoJson.

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to parse a JSON document in an HTTP response.
@ -53,6 +53,7 @@ void setup() {
client.println(F("Connection: close"));
if (client.println() == 0) {
Serial.println(F("Failed to send request"));
client.stop();
return;
}
@ -63,6 +64,7 @@ void setup() {
if (strcmp(status + 9, "200 OK") != 0) {
Serial.print(F("Unexpected response: "));
Serial.println(status);
client.stop();
return;
}
@ -70,6 +72,7 @@ void setup() {
char endOfHeaders[] = "\r\n\r\n";
if (!client.find(endOfHeaders)) {
Serial.println(F("Invalid response"));
client.stop();
return;
}
@ -82,7 +85,8 @@ void setup() {
DeserializationError error = deserializeJson(doc, client);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
Serial.println(error.f_str());
client.stop();
return;
}
@ -101,6 +105,12 @@ void loop() {
// not used in this example
}
// Performance issue?
// ------------------
//
// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
// See: https://arduinojson.org/v6/how-to/improve-speed/
// See also
// --------
//

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to deserialize a JSON document with ArduinoJson.
@ -42,7 +42,7 @@ void setup() {
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
Serial.println(error.f_str());
return;
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to implement an HTTP server that sends a JSON document
@ -46,7 +46,8 @@ void loop() {
EthernetClient client = server.available();
// Do we have a client?
if (!client) return;
if (!client)
return;
Serial.println(F("New client"));
@ -96,6 +97,12 @@ void loop() {
client.stop();
}
// Performance issue?
// ------------------
//
// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
// See: https://arduinojson.org/v6/how-to/improve-speed/
// See also
// --------
//

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to send a JSON document to a UDP socket.
@ -86,6 +86,12 @@ void loop() {
delay(10000);
}
// Performance issue?
// ------------------
//
// EthernetUDP is an unbuffered stream, which is not optimal for ArduinoJson.
// See: https://arduinojson.org/v6/how-to/improve-speed/
// See also
// --------
//

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to deserialize a MessagePack document with
@ -50,7 +50,7 @@ void setup() {
// Test if parsing succeeded.
if (error) {
Serial.print("deserializeMsgPack() failed: ");
Serial.println(error.c_str());
Serial.println(error.f_str());
return;
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows the different ways you can use Flash strings with

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows the different ways you can use String with ArduinoJson.

View File

@ -0,0 +1,4 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components("@PROJECT_NAME@")

View File

@ -1,7 +1,3 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# MIT License
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options(
-pedantic
@ -32,9 +28,20 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
-std=c++98
)
endif()
if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND (NOT ${COVERAGE}))
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
add_compile_options(
-Wstrict-null-sentinel
-Wno-vla # Allow VLA in tests
@ -62,27 +69,32 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND (NOT ${COVERAGE}))
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND (NOT ${COVERAGE}))
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_options(
/W4 # Set warning level
/WX # Treats all compiler warnings as errors.
)
endif()
add_subdirectory(ElementProxy)
add_subdirectory(IntegrationTests)
add_subdirectory(JsonArray)
add_subdirectory(JsonDeserializer)
add_subdirectory(JsonDocument)
add_subdirectory(JsonObject)
add_subdirectory(JsonSerializer)
add_subdirectory(JsonVariant)
add_subdirectory(MemberProxy)
add_subdirectory(MemoryPool)
add_subdirectory(Misc)
add_subdirectory(MixedConfiguration)
add_subdirectory(MsgPackDeserializer)
add_subdirectory(MsgPackSerializer)
add_subdirectory(Numbers)
add_subdirectory(TextFormatter)
if (NOT MSVC_VERSION LESS 1910) # >= Visual Studio 2017
add_compile_options(
/Zc:__cplusplus # Enable updated __cplusplus macro
)
endif()
endif()

10
extras/ci/particle.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh -ex
BOARD=$1
cd "$(dirname "$0")/../../"
cp extras/particle/src/smocktest.ino src/
cp extras/particle/project.properties ./
particle compile "$BOARD"

View File

@ -1,8 +1,6 @@
#!/bin/sh -eux
pip install --user platformio
rm -r test
BOARD=$1
case $BOARD in
uno)

View File

@ -0,0 +1,54 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# MIT License
if(MSVC)
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
endif()
add_executable(msgpack_reproducer
msgpack_fuzzer.cpp
reproducer.cpp
)
target_link_libraries(msgpack_reproducer
ArduinoJson
)
add_executable(json_reproducer
json_fuzzer.cpp
reproducer.cpp
)
target_link_libraries(json_reproducer
ArduinoJson
)
macro(add_fuzzer name)
set(FUZZER "${name}_fuzzer")
set(CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus")
set(SEED_CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_seed_corpus")
add_executable("${FUZZER}"
"${name}_fuzzer.cpp"
)
target_link_libraries("${FUZZER}"
ArduinoJson
)
set_target_properties("${FUZZER}"
PROPERTIES
COMPILE_FLAGS
"-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
LINK_FLAGS
"-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
)
add_test(
NAME
"${FUZZER}"
COMMAND
"${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1
)
endmacro()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
add_fuzzer(json)
add_fuzzer(msgpack)
endif()

View File

@ -1,6 +1,6 @@
# CAUTION: this file is invoked by https://github.com/google/oss-fuzz
CXXFLAGS += -I../src -DARDUINOJSON_DEBUG
CXXFLAGS += -I../../src -DARDUINOJSON_DEBUG=1
all: \
$(OUT)/json_fuzzer \
@ -10,7 +10,7 @@ all: \
$(OUT)/msgpack_fuzzer_seed_corpus.zip \
$(OUT)/msgpack_fuzzer.options
$(OUT)/%_fuzzer: %_fuzzer.cpp $(shell find ../src -type f)
$(OUT)/%_fuzzer: %_fuzzer.cpp $(shell find ../../src -type f)
$(CXX) $(CXXFLAGS) $< -o$@ $(LIB_FUZZING_ENGINE)
$(OUT)/%_fuzzer_seed_corpus.zip: %_seed_corpus/*

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
// This file is NOT use by Google's OSS fuzz
@ -21,7 +21,7 @@ std::vector<uint8_t> read(const char* path) {
}
fseek(f, 0, SEEK_END);
size_t size = ftell(f);
size_t size = static_cast<size_t>(ftell(f));
fseek(f, 0, SEEK_SET);
std::vector<uint8_t> buffer(size);

View File

@ -0,0 +1 @@
name=ArduinoJsonCI

View File

@ -0,0 +1,5 @@
#include "ArduinoJson.h"
void setup() {}
void loop() {}

View File

@ -3,13 +3,14 @@
TAG=$(git describe)
OUTPUT="ArduinoJson-$TAG.zip"
cd $(dirname $0)/../..
cd $(dirname $0)/../../..
# remove existing file
rm -f $OUTPUT
# create zip
7z a $OUTPUT \
-xr!.vs \
ArduinoJson/CHANGELOG.md \
ArduinoJson/examples \
ArduinoJson/src \

View File

@ -0,0 +1,82 @@
#!/bin/bash
set -e
TAG=$(git describe)
RE_RELATIVE_INCLUDE='^#include[[:space:]]*"(.*)"'
RE_ABSOLUTE_INCLUDE='^#include[[:space:]]*<(ArduinoJson/.*)>'
RE_SYSTEM_INCLUDE='^#include[[:space:]]*<(.*)>'
RE_EMPTY='^(#pragma[[:space:]]+once)?[[:space:]]*(//.*)?$'
SRC_DIRECTORY="$(realpath "$(dirname $0)/../../src")"
declare -A INCLUDED
process()
{
local PARENT=$1
local FOLDER=$(dirname $1)
local SHOW_COMMENT=$2
while IFS= read -r LINE; do
if [[ $LINE =~ $RE_ABSOLUTE_INCLUDE ]]; then
local CHILD=${BASH_REMATCH[1]}
local CHILD_PATH
CHILD_PATH=$(realpath "$SRC_DIRECTORY/$CHILD")
echo "$PARENT -> $CHILD" >&2
if [[ ! ${INCLUDED[$CHILD_PATH]} ]]; then
INCLUDED[$CHILD_PATH]=true
process "$CHILD" false
fi
elif [[ $LINE =~ $RE_RELATIVE_INCLUDE ]]; then
local CHILD=${BASH_REMATCH[1]}
pushd "$FOLDER" > /dev/null
local CHILD_PATH
CHILD_PATH=$(realpath "$CHILD")
echo "$PARENT -> $CHILD" >&2
if [[ ! ${INCLUDED[$CHILD_PATH]} ]]; then
INCLUDED[$CHILD_PATH]=true
process "$CHILD" false
fi
popd > /dev/null
elif [[ $LINE =~ $RE_SYSTEM_INCLUDE ]]; then
local CHILD=${BASH_REMATCH[1]}
echo "$PARENT -> <$CHILD>" >&2
if [[ ! ${INCLUDED[$CHILD]} ]]; then
echo "#include <$CHILD>"
INCLUDED[$CHILD]=true
fi
elif [[ "${SHOW_COMMENT}" = "true" ]] ; then
echo "$LINE"
elif [[ ! $LINE =~ $RE_EMPTY ]]; then
echo "$LINE"
fi
done < $PARENT
}
simplify_namespaces() {
perl -p0i -e 's|\} // namespace ARDUINOJSON_NAMESPACE\r?\nnamespace ARDUINOJSON_NAMESPACE \{\r?\n||igs' "$1"
rm -f "$1.bak"
}
cd $(dirname $0)/../..
INCLUDED=()
process src/ArduinoJson.h true > ../ArduinoJson-$TAG.h
simplify_namespaces ../ArduinoJson-$TAG.h
g++ -x c++ -c -o ../smoketest.o - <<END
#include "../ArduinoJson-$TAG.h"
int main() {
StaticJsonDocument<300> doc;
deserializeJson(doc, "{}");
}
END
INCLUDED=()
process src/ArduinoJson.hpp true > ../ArduinoJson-$TAG.hpp
simplify_namespaces ../ArduinoJson-$TAG.hpp
g++ -x c++ -c -o ../smoketest.o - <<END
#include "../ArduinoJson-$TAG.hpp"
int main() {
ArduinoJson::StaticJsonDocument<300> doc;
ArduinoJson::deserializeJson(doc, "{}");
}
END

View File

@ -2,7 +2,7 @@
set -eu
SOURCE_DIR="$(dirname "$0")/.."
SOURCE_DIR="$(dirname "$0")/../.."
WORK_DIR=$(mktemp -d)
trap 'rm -rf "$WORK_DIR"' EXIT

23
scripts/publish.sh → extras/scripts/publish.sh Normal file → Executable file
View File

@ -2,7 +2,7 @@
set -eu
cd "$(dirname "$0")/.."
cd "$(dirname "$0")/../.."
VERSION="$1"
DATE=$(date +%F)
@ -14,19 +14,22 @@ update_version_in_source () {
UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG}))
sed -i~ -bE "s/version=$VERSION_REGEX/version=$VERSION/; s|ardu-badge.com/ArduinoJson/$VERSION_REGEX|ardu-badge.com/ArduinoJson/$VERSION|; " README.md
rm README.md*~
rm README.md~
sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md
rm CHANGELOG.md*~
rm CHANGELOG.md~
sed -i~ -bE "s/(project\\s*\\(ArduinoJson\\s+VERSION\\s+).*?\\)/\\1$MAJOR.$MINOR.$REVISION)/" CMakeLists.txt
rm CMakeLists.txt~
sed -i~ -bE "s/\"version\":.*$/\"version\": \"$VERSION\",/" library.json
rm library.json*~
rm library.json~
sed -i~ -bE "s/version=.*$/version=$VERSION/" library.properties
rm library.properties*~
rm library.properties~
sed -i~ -bE "s/version: .*$/version: $VERSION.{build}/" appveyor.yml
rm appveyor.yml*~
rm appveyor.yml~
sed -i~ -bE \
-e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \
@ -38,7 +41,7 @@ update_version_in_source () {
}
commit_new_version () {
git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml
git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml CMakeLists.txt
git commit -m "Set version to $VERSION"
}
@ -56,6 +59,6 @@ commit_new_version
add_tag
push
scripts/build-arduino-package.sh
scripts/build-single-header.sh
scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h"
extras/scripts/build-arduino-package.sh
extras/scripts/build-single-header.sh
extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h"

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to generate a JSON document with ArduinoJson.

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to deserialize a JSON document with ArduinoJson.

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to generate a JSON document with ArduinoJson.

View File

View File

@ -0,0 +1,24 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# MIT License
add_subdirectory(catch)
link_libraries(ArduinoJson catch)
include_directories(Helpers)
add_subdirectory(FailingBuilds)
add_subdirectory(IntegrationTests)
add_subdirectory(JsonArray)
add_subdirectory(JsonDeserializer)
add_subdirectory(JsonDocument)
add_subdirectory(JsonObject)
add_subdirectory(JsonSerializer)
add_subdirectory(JsonVariant)
add_subdirectory(MemoryPool)
add_subdirectory(Misc)
add_subdirectory(MixedConfiguration)
add_subdirectory(MsgPackDeserializer)
add_subdirectory(MsgPackSerializer)
add_subdirectory(Numbers)
add_subdirectory(TextFormatter)

View File

@ -0,0 +1,41 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# MIT License
macro(build_should_fail target)
set_target_properties(${target}
PROPERTIES
EXCLUDE_FROM_ALL TRUE
EXCLUDE_FROM_DEFAULT_BUILD TRUE
)
add_test(
NAME
${target}
COMMAND
${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}
)
set_tests_properties(${target}
PROPERTIES
WILL_FAIL TRUE
)
endmacro()
add_executable(Issue978 Issue978.cpp)
build_should_fail(Issue978)
add_executable(Issue1189 Issue1189.cpp)
build_should_fail(Issue1189)
add_executable(read_long_long read_long_long.cpp)
set_property(TARGET read_long_long PROPERTY CXX_STANDARD 11)
build_should_fail(read_long_long)
add_executable(write_long_long write_long_long.cpp)
set_property(TARGET write_long_long PROPERTY CXX_STANDARD 11)
build_should_fail(write_long_long)
add_executable(delete_jsondocument delete_jsondocument.cpp)
build_should_fail(delete_jsondocument)

View File

@ -0,0 +1,13 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
// a function should not be able to get a JsonDocument by value
void f(JsonDocument) {}
int main() {
DynamicJsonDocument doc(1024);
f(doc);
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>

View File

@ -0,0 +1,12 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
struct Stream {};
int main() {
JsonDocument* doc = new DynamicJsonDocument(42);
delete doc;
}

View File

@ -0,0 +1,20 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#define ARDUINOJSON_USE_LONG_LONG 0
#include <ArduinoJson.h>
#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8
#error This test requires sizeof(long) < 8
#endif
#if !ARDUINOJSON_HAS_LONG_LONG
#error This test requires C++11
#endif
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(long long)
int main() {
DynamicJsonDocument doc(1024);
doc["dummy"].as<long long>();
}

View File

@ -0,0 +1,19 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#define ARDUINOJSON_USE_LONG_LONG 0
#include <ArduinoJson.h>
#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8
#error This test requires sizeof(long) < 8
#endif
#if !ARDUINOJSON_HAS_LONG_LONG
#error This test requires C++11
#endif
int main() {
DynamicJsonDocument doc(1024);
doc["dummy"] = static_cast<long long>(42);
}

View File

@ -0,0 +1,8 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include "api/Stream.h"
#include "api/String.h"

View File

@ -0,0 +1,26 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <sstream>
class CustomReader {
std::stringstream _stream;
public:
CustomReader(const char* input) : _stream(input) {}
int read() {
return _stream.get();
}
size_t readBytes(char* buffer, size_t length) {
_stream.read(buffer, static_cast<std::streamsize>(length));
return static_cast<size_t>(_stream.gcount());
}
private:
CustomReader(const CustomReader&);
};

View File

@ -0,0 +1,14 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
// Reproduces Arduino's Stream class
class Stream // : public Print
{
public:
virtual ~Stream() {}
virtual int read() = 0;
virtual size_t readBytes(char *buffer, size_t length) = 0;
};

View File

@ -0,0 +1,45 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <string>
// Reproduces Arduino's String class
class String {
public:
String() {}
explicit String(const char* s) : _str(s) {}
String& operator+=(const char* rhs) {
_str += rhs;
return *this;
}
size_t length() const {
return _str.size();
}
const char* c_str() const {
return _str.c_str();
}
bool operator==(const char* s) const {
return _str == s;
}
friend std::ostream& operator<<(std::ostream& lhs, const ::String& rhs) {
lhs << rhs._str;
return lhs;
}
private:
std::string _str;
};
class StringSumHelper;
inline bool operator==(const std::string& lhs, const ::String& rhs) {
return lhs == rhs.c_str();
}

View File

@ -0,0 +1,42 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <stdint.h> // uint8_t
#include <string.h> // strcmp, strlen...
#define PROGMEM
class __FlashStringHelper;
inline const void* convertPtrToFlash(const void* s) {
return reinterpret_cast<const char*>(s) + 42;
}
inline const void* convertFlashToPtr(const void* s) {
return reinterpret_cast<const char*>(s) - 42;
}
#define PSTR(X) reinterpret_cast<const char*>(convertPtrToFlash(X))
#define F(X) reinterpret_cast<const __FlashStringHelper*>(PSTR(X))
inline uint8_t pgm_read_byte(const void* p) {
return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p));
}
inline void* pgm_read_ptr(const void* p) {
return *reinterpret_cast<void* const*>(convertFlashToPtr(p));
}
inline float pgm_read_float(const void* p) {
return *reinterpret_cast<const float*>(convertFlashToPtr(p));
}
inline uint32_t pgm_read_dword(const void* p) {
return *reinterpret_cast<const uint32_t*>(convertFlashToPtr(p));
}
#define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \
static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \
static type const* name = reinterpret_cast<type const*>( \
convertPtrToFlash(ARDUINOJSON_CONCAT2(name, _progmem)));

View File

@ -1,11 +1,12 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# Copyright Benoit Blanchon 2014-2021
# MIT License
add_executable(IntegrationTests
gbathree.cpp
issue772.cpp
round_trip.cpp
openweathermap.cpp
)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
@ -15,5 +16,4 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
)
endif()
target_link_libraries(IntegrationTests catch)
add_test(IntegrationTests IntegrationTests)

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# Copyright Benoit Blanchon 2014-2021
# MIT License
add_executable(JsonArrayTests
@ -19,5 +19,4 @@ add_executable(JsonArrayTests
undefined.cpp
)
target_link_libraries(JsonArrayTests catch)
add_test(JsonArray JsonArrayTests)

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -102,13 +102,13 @@ TEST_CASE("JsonArray::add()") {
SECTION("should duplicate char*") {
array.add(const_cast<char*>("world"));
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6);
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5);
REQUIRE(expectedSize == doc.memoryUsage());
}
SECTION("should duplicate std::string") {
array.add(std::string("world"));
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6);
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5);
REQUIRE(expectedSize == doc.memoryUsage());
}

View File

@ -0,0 +1,279 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("copyArray()") {
SECTION("int[] -> JsonArray") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
char json[32];
int source[] = {1, 2, 3};
bool ok = copyArray(source, array);
CHECK(ok);
serializeJson(array, json);
CHECK(std::string("[1,2,3]") == json);
}
SECTION("std::string[] -> JsonArray") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
char json[32];
std::string source[] = {"a", "b", "c"};
bool ok = copyArray(source, array);
CHECK(ok);
serializeJson(array, json);
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
}
SECTION("int[] -> JsonDocument") {
DynamicJsonDocument doc(4096);
char json[32];
int source[] = {1, 2, 3};
bool ok = copyArray(source, doc);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("[1,2,3]") == json);
}
SECTION("int[] -> MemberProxy") {
DynamicJsonDocument doc(4096);
char json[32];
int source[] = {1, 2, 3};
bool ok = copyArray(source, doc["data"]);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("{\"data\":[1,2,3]}") == json);
}
SECTION("int[] -> JsonArray, but not enough memory") {
const size_t SIZE = JSON_ARRAY_SIZE(2);
StaticJsonDocument<SIZE> doc;
JsonArray array = doc.to<JsonArray>();
char json[32];
int source[] = {1, 2, 3};
bool ok = copyArray(source, array);
REQUIRE_FALSE(ok);
serializeJson(array, json);
CHECK(std::string("[1,2]") == json);
}
SECTION("int[][] -> JsonArray") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
char json[32];
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
bool ok = copyArray(source, array);
CHECK(ok);
serializeJson(array, json);
CHECK(std::string("[[1,2,3],[4,5,6]]") == json);
}
SECTION("int[][] -> MemberProxy") {
DynamicJsonDocument doc(4096);
char json[32];
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
bool ok = copyArray(source, doc["data"]);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("{\"data\":[[1,2,3],[4,5,6]]}") == json);
}
SECTION("int[][] -> JsonDocument") {
DynamicJsonDocument doc(4096);
char json[32];
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
bool ok = copyArray(source, doc);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("[[1,2,3],[4,5,6]]") == json);
}
SECTION("int[][] -> JsonArray, but not enough memory") {
const size_t SIZE =
JSON_ARRAY_SIZE(2) + JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(2);
StaticJsonDocument<SIZE> doc;
JsonArray array = doc.to<JsonArray>();
char json[32] = "";
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
CAPTURE(SIZE)
bool ok = copyArray(source, array);
CAPTURE(doc.memoryUsage());
CHECK_FALSE(ok);
serializeJson(array, json);
CHECK(std::string("[[1,2,3],[4,5]]") == json);
}
SECTION("JsonArray -> int[], with more space than needed") {
DynamicJsonDocument doc(4096);
char json[] = "[1,2,3]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
int destination[4] = {0};
size_t result = copyArray(array, destination);
CHECK(3 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
CHECK(3 == destination[2]);
CHECK(0 == destination[3]);
}
SECTION("JsonArray -> int[], without enough space") {
DynamicJsonDocument doc(4096);
char json[] = "[1,2,3]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
int destination[2] = {0};
size_t result = copyArray(array, destination);
CHECK(2 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
}
SECTION("JsonArray -> std::string[]") {
DynamicJsonDocument doc(4096);
char json[] = "[\"a\",\"b\",\"c\"]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
std::string destination[4];
size_t result = copyArray(array, destination);
CHECK(3 == result);
CHECK("a" == destination[0]);
CHECK("b" == destination[1]);
CHECK("c" == destination[2]);
CHECK("" == destination[3]);
}
SECTION("JsonDocument -> int[]") {
DynamicJsonDocument doc(4096);
char json[] = "[1,2,3]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[4] = {0};
size_t result = copyArray(doc, destination);
CHECK(3 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
CHECK(3 == destination[2]);
CHECK(0 == destination[3]);
}
SECTION("MemberProxy -> int[]") {
DynamicJsonDocument doc(4096);
char json[] = "{\"data\":[1,2,3]}";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[4] = {0};
size_t result = copyArray(doc["data"], destination);
CHECK(3 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
CHECK(3 == destination[2]);
CHECK(0 == destination[3]);
}
SECTION("ElementProxy -> int[]") {
DynamicJsonDocument doc(4096);
char json[] = "[[1,2,3]]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[4] = {0};
size_t result = copyArray(doc[0], destination);
CHECK(3 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
CHECK(3 == destination[2]);
CHECK(0 == destination[3]);
}
SECTION("JsonArray -> int[][]") {
DynamicJsonDocument doc(4096);
char json[] = "[[1,2],[3],[4]]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
int destination[3][2] = {{0}};
copyArray(array, destination);
CHECK(1 == destination[0][0]);
CHECK(2 == destination[0][1]);
CHECK(3 == destination[1][0]);
CHECK(0 == destination[1][1]);
CHECK(4 == destination[2][0]);
CHECK(0 == destination[2][1]);
}
SECTION("JsonDocument -> int[][]") {
DynamicJsonDocument doc(4096);
char json[] = "[[1,2],[3],[4]]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[3][2] = {{0}};
copyArray(doc, destination);
CHECK(1 == destination[0][0]);
CHECK(2 == destination[0][1]);
CHECK(3 == destination[1][0]);
CHECK(0 == destination[1][1]);
CHECK(4 == destination[2][0]);
CHECK(0 == destination[2][1]);
}
SECTION("MemberProxy -> int[][]") {
DynamicJsonDocument doc(4096);
char json[] = "{\"data\":[[1,2],[3],[4]]}";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[3][2] = {{0}};
copyArray(doc["data"], destination);
CHECK(1 == destination[0][0]);
CHECK(2 == destination[0][1]);
CHECK(3 == destination[1][0]);
CHECK(0 == destination[1][1]);
CHECK(4 == destination[2][0]);
CHECK(0 == destination[2][1]);
}
}

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