When using const nlohmann::json j{R"([...])"_json}; a different result is returned compared to const nlohmann::json j = nlohmann::json::parse(R"([...])");
- Please describe the steps to reproduce the issue. Can you provide a small but working code example?
This issue was only reproducible on Ubuntu 18.04 and it did not happen on macOS 10.13.3.
const nlohmann::json body_json{R"([
{
"AuthMode": "",
"Certificate": "",
"CertificateType": "",
"Credential": "",
"CredentialType": "",
"Password": "password",
"Path": "{\n \"clientId\" : \"9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba\",\n \"service\" : \"rabbitmq\",\n \"enabled\" : true,\n \"protocol\" : \"amqp\",\n \"created\" : \"2018-06-14T17:44:05Z\",\n \"updated\" : \"2018-06-14T17:44:05Z\",\n \"connections\" : [ {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"exchange\",\n \"value\" : \"0\"\n }, {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"queue\",\n \"value\" : \"device\"\n } ]\n}",
"ServerType": "RabbitMQ",
"UseExistingConnection": true,
"UserName": "9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba"
}
])"_json};
const nlohmann::json body_json = nlohmann::json::parse(R"([
{
"AuthMode": "",
"Certificate": "",
"CertificateType": "",
"Credential": "",
"CredentialType": "",
"Password": "password",
"Path": "{\n \"clientId\" : \"9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba\",\n \"service\" : \"rabbitmq\",\n \"enabled\" : true,\n \"protocol\" : \"amqp\",\n \"created\" : \"2018-06-14T17:44:05Z\",\n \"updated\" : \"2018-06-14T17:44:05Z\",\n \"connections\" : [ {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"exchange\",\n \"value\" : \"0\"\n }, {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"queue\",\n \"value\" : \"device\"\n } ]\n}",
"ServerType": "RabbitMQ",
"UseExistingConnection": true,
"UserName": "9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba"
}
])");
Both of these parse correctly in macOS to the following value:
[
{
"AuthMode": "",
"Certificate": "",
"CertificateType": "",
"Credential": "",
"CredentialType": "",
"Password": "password",
"Path": "{\n \"clientId\" : \"9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba\",\n \"service\" : \"rabbitmq\",\n \"enabled\" : true,\n \"protocol\" : \"amqp\",\n \"created\" : \"2018-06-14T17:44:05Z\",\n \"updated\" : \"2018-06-14T17:44:05Z\",\n \"connections\" : [ {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"exchange\",\n \"value\" : \"0\"\n }, {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"queue\",\n \"value\" : \"device\"\n } ]\n}",
"ServerType": "RabbitMQ",
"UseExistingConnection": true,
"UserName": "9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba"
}
]
The example using ::parse correctly parses to the above value in Ubuntu 18.04, however, the _json implementation parses to the following:
[
[
{
"AuthMode": "",
"Certificate": "",
"CertificateType": "",
"Credential": "",
"CredentialType": "",
"Password": "password",
"Path": "{\n \"clientId\" : \"9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba\",\n \"service\" : \"rabbitmq\",\n \"enabled\" : true,\n \"protocol\" : \"amqp\",\n \"created\" : \"2018-06-14T17:44:05Z\",\n \"updated\" : \"2018-06-14T17:44:05Z\",\n \"connections\" : [ {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"exchange\",\n \"value\" : \"0\"\n }, {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"queue\",\n \"value\" : \"device\"\n } ]\n}",
"ServerType": "RabbitMQ",
"UseExistingConnection": true,
"UserName": "9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba"
}
]
]
Compiler Version:
g++ (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Currently not listed as supported.
Library Version: 3.1.2 (release)
Testing
Dockerfile used to run the unit tests:
FROM ubuntu:18.04
ENV HOME /root
ENV DEBIAN_FRONTEND noninteractive
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get update
RUN apt-get install -y software-properties-common cmake git build-essential curl libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev librabbitmq-dev
RUN git clone -b v3.1.2 https://github.com/nlohmann/json.git
WORKDIR json/build
RUN cmake ..
RUN cmake --build .
ENTRYPOINT ctest --output-on-failure
Test project /json/build
Start 1: test-algorithms_default
1/78 Test #1: test-algorithms_default ............. Passed 0.01 sec
Start 2: test-algorithms_all
2/78 Test #2: test-algorithms_all ................. Passed 0.00 sec
Start 3: test-allocator_default
3/78 Test #3: test-allocator_default .............. Passed 0.00 sec
Start 4: test-allocator_all
4/78 Test #4: test-allocator_all .................. Passed 0.00 sec
Start 5: test-alt-string_default
5/78 Test #5: test-alt-string_default ............. Passed 0.00 sec
Start 6: test-alt-string_all
6/78 Test #6: test-alt-string_all ................. Passed 0.00 sec
Start 7: test-capacity_default
7/78 Test #7: test-capacity_default ............... Passed 0.01 sec
Start 8: test-capacity_all
8/78 Test #8: test-capacity_all ................... Passed 0.01 sec
Start 9: test-cbor_default
9/78 Test #9: test-cbor_default ................... Passed 1.61 sec
Start 10: test-cbor_all
10/78 Test #10: test-cbor_all ....................... Passed 24.93 sec
Start 11: test-class_const_iterator_default
11/78 Test #11: test-class_const_iterator_default ... Passed 0.00 sec
Start 12: test-class_const_iterator_all
12/78 Test #12: test-class_const_iterator_all ....... Passed 0.00 sec
Start 13: test-class_iterator_default
13/78 Test #13: test-class_iterator_default ......... Passed 0.00 sec
Start 14: test-class_iterator_all
14/78 Test #14: test-class_iterator_all ............. Passed 0.00 sec
Start 15: test-class_lexer_default
15/78 Test #15: test-class_lexer_default ............ Passed 0.00 sec
Start 16: test-class_lexer_all
16/78 Test #16: test-class_lexer_all ................ Passed 0.00 sec
Start 17: test-class_parser_default
17/78 Test #17: test-class_parser_default ........... Passed 0.08 sec
Start 18: test-class_parser_all
18/78 Test #18: test-class_parser_all ............... Passed 0.08 sec
Start 19: test-comparison_default
19/78 Test #19: test-comparison_default ............. Passed 0.01 sec
Start 20: test-comparison_all
20/78 Test #20: test-comparison_all ................. Passed 0.01 sec
Start 21: test-concepts_default
21/78 Test #21: test-concepts_default ............... Passed 0.00 sec
Start 22: test-concepts_all
22/78 Test #22: test-concepts_all ................... Passed 0.00 sec
Start 23: test-constructor1_default
23/78 Test #23: test-constructor1_default ........... Passed 0.04 sec
Start 24: test-constructor1_all
24/78 Test #24: test-constructor1_all ............... Passed 0.03 sec
Start 25: test-constructor2_default
25/78 Test #25: test-constructor2_default ........... Passed 0.00 sec
Start 26: test-constructor2_all
26/78 Test #26: test-constructor2_all ............... Passed 0.00 sec
Start 27: test-convenience_default
27/78 Test #27: test-convenience_default ............ Passed 0.00 sec
Start 28: test-convenience_all
28/78 Test #28: test-convenience_all ................ Passed 0.00 sec
Start 29: test-conversions_default
29/78 Test #29: test-conversions_default ............ Passed 0.03 sec
Start 30: test-conversions_all
30/78 Test #30: test-conversions_all ................ Passed 0.03 sec
Start 31: test-deserialization_default
31/78 Test #31: test-deserialization_default ........ Passed 0.01 sec
Start 32: test-deserialization_all
32/78 Test #32: test-deserialization_all ............ Passed 0.01 sec
Start 33: test-element_access1_default
33/78 Test #33: test-element_access1_default ........ Passed 0.01 sec
Start 34: test-element_access1_all
34/78 Test #34: test-element_access1_all ............ Passed 0.01 sec
Start 35: test-element_access2_default
35/78 Test #35: test-element_access2_default ........ Passed 0.02 sec
Start 36: test-element_access2_all
36/78 Test #36: test-element_access2_all ............ Passed 0.02 sec
Start 37: test-inspection_default
37/78 Test #37: test-inspection_default ............. Passed 4.69 sec
Start 38: test-inspection_all
38/78 Test #38: test-inspection_all ................. Passed 4.65 sec
Start 39: test-items_default
39/78 Test #39: test-items_default .................. Passed 0.01 sec
Start 40: test-items_all
40/78 Test #40: test-items_all ...................... Passed 0.01 sec
Start 41: test-iterators1_default
41/78 Test #41: test-iterators1_default ............. Passed 0.02 sec
Start 42: test-iterators1_all
42/78 Test #42: test-iterators1_all ................. Passed 0.02 sec
Start 43: test-iterators2_default
43/78 Test #43: test-iterators2_default ............. Passed 0.04 sec
Start 44: test-iterators2_all
44/78 Test #44: test-iterators2_all ................. Passed 0.03 sec
Start 45: test-json_patch_default
45/78 Test #45: test-json_patch_default ............. Passed 0.02 sec
Start 46: test-json_patch_all
46/78 Test #46: test-json_patch_all ................. Passed 0.02 sec
Start 47: test-json_pointer_default
47/78 Test #47: test-json_pointer_default ........... Passed 0.00 sec
Start 48: test-json_pointer_all
48/78 Test #48: test-json_pointer_all ............... Passed 0.00 sec
Start 49: test-merge_patch_default
49/78 Test #49: test-merge_patch_default ............ Passed 0.00 sec
Start 50: test-merge_patch_all
50/78 Test #50: test-merge_patch_all ................ Passed 0.00 sec
Start 51: test-meta_default
51/78 Test #51: test-meta_default ................... Passed 0.00 sec
Start 52: test-meta_all
52/78 Test #52: test-meta_all ....................... Passed 0.00 sec
Start 53: test-modifiers_default
53/78 Test #53: test-modifiers_default .............. Passed 0.01 sec
Start 54: test-modifiers_all
54/78 Test #54: test-modifiers_all .................. Passed 0.01 sec
Start 55: test-msgpack_default
55/78 Test #55: test-msgpack_default ................ Passed 1.47 sec
Start 56: test-msgpack_all
56/78 Test #56: test-msgpack_all .................... Passed 25.01 sec
Start 57: test-noexcept_default
57/78 Test #57: test-noexcept_default ............... Passed 0.00 sec
Start 58: test-noexcept_all
58/78 Test #58: test-noexcept_all ................... Passed 0.00 sec
Start 59: test-pointer_access_default
59/78 Test #59: test-pointer_access_default ......... Passed 0.00 sec
Start 60: test-pointer_access_all
60/78 Test #60: test-pointer_access_all ............. Passed 0.00 sec
Start 61: test-readme_default
61/78 Test #61: test-readme_default ................. Passed 0.00 sec
Start 62: test-readme_all
62/78 Test #62: test-readme_all ..................... Passed 0.00 sec
Start 63: test-reference_access_default
63/78 Test #63: test-reference_access_default ....... Passed 0.00 sec
Start 64: test-reference_access_all
64/78 Test #64: test-reference_access_all ........... Passed 0.00 sec
Start 65: test-regression_default
65/78 Test #65: test-regression_default ............. Passed 4.65 sec
Start 66: test-regression_all
66/78 Test #66: test-regression_all ................. Passed 4.78 sec
Start 67: test-serialization_default
67/78 Test #67: test-serialization_default .......... Passed 0.00 sec
Start 68: test-serialization_all
68/78 Test #68: test-serialization_all .............. Passed 0.00 sec
Start 69: test-testsuites_default
69/78 Test #69: test-testsuites_default ............. Passed 0.10 sec
Start 70: test-testsuites_all
70/78 Test #70: test-testsuites_all ................. Passed 0.05 sec
Start 71: test-to_chars_default
71/78 Test #71: test-to_chars_default ............... Passed 0.00 sec
Start 72: test-to_chars_all
72/78 Test #72: test-to_chars_all ................... Passed 0.00 sec
Start 73: test-ubjson_default
73/78 Test #73: test-ubjson_default ................. Passed 0.80 sec
Start 74: test-ubjson_all
74/78 Test #74: test-ubjson_all ..................... Passed 9.23 sec
Start 75: test-udt_default
75/78 Test #75: test-udt_default .................... Passed 0.00 sec
Start 76: test-udt_all
76/78 Test #76: test-udt_all ........................ Passed 0.00 sec
Start 77: test-unicode_default
77/78 Test #77: test-unicode_default ................ Passed 0.01 sec
Start 78: test-unicode_all
78/78 Test #78: test-unicode_all .................... Passed 145.24 sec
100% tests passed, 0 tests failed out of 78
Label Time Summary:
all = 214.25 sec*proc (39 tests)
default = 13.70 sec*proc (39 tests)
Total Test time (real) = 227.99 sec
When using
const nlohmann::json j{R"([...])"_json};a different result is returned compared toconst nlohmann::json j = nlohmann::json::parse(R"([...])");This issue was only reproducible on Ubuntu 18.04 and it did not happen on macOS 10.13.3.
Both of these parse correctly in macOS to the following value:
[ { "AuthMode": "", "Certificate": "", "CertificateType": "", "Credential": "", "CredentialType": "", "Password": "password", "Path": "{\n \"clientId\" : \"9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba\",\n \"service\" : \"rabbitmq\",\n \"enabled\" : true,\n \"protocol\" : \"amqp\",\n \"created\" : \"2018-06-14T17:44:05Z\",\n \"updated\" : \"2018-06-14T17:44:05Z\",\n \"connections\" : [ {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"exchange\",\n \"value\" : \"0\"\n }, {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"queue\",\n \"value\" : \"device\"\n } ]\n}", "ServerType": "RabbitMQ", "UseExistingConnection": true, "UserName": "9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba" } ]The example using ::parse correctly parses to the above value in Ubuntu 18.04, however, the _json implementation parses to the following:
[ [ { "AuthMode": "", "Certificate": "", "CertificateType": "", "Credential": "", "CredentialType": "", "Password": "password", "Path": "{\n \"clientId\" : \"9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba\",\n \"service\" : \"rabbitmq\",\n \"enabled\" : true,\n \"protocol\" : \"amqp\",\n \"created\" : \"2018-06-14T17:44:05Z\",\n \"updated\" : \"2018-06-14T17:44:05Z\",\n \"connections\" : [ {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"exchange\",\n \"value\" : \"0\"\n }, {\n \"host\" : \"127.0.0.1\",\n \"port\" : 5672,\n \"virtualHost\" : \"/\",\n \"type\" : \"queue\",\n \"value\" : \"device\"\n } ]\n}", "ServerType": "RabbitMQ", "UseExistingConnection": true, "UserName": "9dfeaea7-7d3f-4ce9-b4ac-e17badddf2ba" } ] ]Compiler Version:
g++ (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Currently not listed as supported.
Library Version: 3.1.2 (release)
Testing
Dockerfile used to run the unit tests: