Closed sbashford closed 4 years ago
The issue is that braces are interpreted as array or object, so json j {1};
creates [1]
rather than 1
. You can fix the example by changing
const auto example{nlohmann::json::parse(R"([{"pi": 3.141}])")};
to
const auto example = nlohmann::json::parse(R"([{"pi": 3.141}])");
I have no idea how to fix this without breaking existing code. Maybe an option like we introduced for implicit conversions?
That solves my use case. Thanks for your quick reply.
The behavior appears to be different on clang 10.0.0. But this is not an issue when using an assignment as you've described.
Duplicate of #2311.
What is the issue you have?
When compiled with gcc 7.5.0, passing a JSON array to
parse
returns an array containing the desired array. This is not the same behavior on clang 10.0.0 where the desired array is instead returned.Please describe the steps to reproduce the issue.
on macOS 10.15.6 with cmake 3.18.1 and brew 2.4.9 in a directory containing the CMakeLists.txt and main.cpp listed below:
brew install gcc@7
cmake -S . -B build -DCMAKE_CXX_COMPILER=/usr/local/bin/g++-7
cmake --build build
./build/example
Can you provide a small but working code example?
What is the expected behavior?
[{"pi":3.141}]
And what is the actual behavior instead?
[[{"pi":3.141}]]
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branch