• Home
  • Raw
  • Download

Lines Matching full:json

2 //  __|  |   __|     |   | |  JSON for Modern C++ (supporting code)
4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json
11 #include <nlohmann/json.hpp>
12 using nlohmann::json;
20 TEST_CASE("JSON patch")
26 // the ordering of members in JSON objects is not significant:
27 json op1 = R"({ "op": "add", "path": "/a/b/c", "value": "foo" })"_json;
28 json op2 = R"({ "path": "/a/b/c", "op": "add", "value": "foo" })"_json;
29 json op3 = R"({ "value": "foo", "path": "/a/b/c", "op": "add" })"_json;
38json const patch1 = R"([{ "op": "add", "path": "/a/b", "value": [ "foo", "bar" ] }])"_json;
44 json const doc1 = R"({ "a": { "foo": 1 } })"_json;
60 json const doc2 = R"({ "q": { "bar": 2 } })"_json;
63 …CHECK_THROWS_WITH_AS(doc2.patch(patch1), "[json.exception.out_of_range.403] key 'a' not found", js…
65 json const doc3 = R"({ "a": {} })"_json;
66 json const patch2 = R"([{ "op": "add", "path": "/a/b/c", "value": 1 }])"_json;
70 …CHECK_THROWS_WITH_AS(doc3.patch(patch2), "[json.exception.out_of_range.403] (/a) key 'b' not found…
72 …CHECK_THROWS_WITH_AS(doc3.patch(patch2), "[json.exception.out_of_range.403] key 'b' not found", js…
80 json const doc = {1, 2, 3, 4};
81 json const patch = {{{"op", "remove"}, {"path", "/1"}}};
82 CHECK(doc.patch(patch) == json({1, 3, 4}));
87 // An example target JSON document:
88 json const doc = R"(
92 // A JSON Patch document:
93 json const patch = R"(
99 // The resulting JSON document:
100 json expected = R"(
111 CHECK(doc.patch(json::diff(doc, expected)) == expected);
116 // An example target JSON document:
117 json const doc = R"(
121 // A JSON Patch document:
122 json const patch = R"(
128 // The resulting JSON document:
129 json expected = R"(
137 CHECK(doc.patch(json::diff(doc, expected)) == expected);
142 // An example target JSON document:
143 json const doc = R"(
150 // A JSON Patch document:
151 json const patch = R"(
157 // The resulting JSON document:
158 json expected = R"(
166 CHECK(doc.patch(json::diff(doc, expected)) == expected);
171 // An example target JSON document:
172 json const doc = R"(
176 // A JSON Patch document:
177 json const patch = R"(
183 // The resulting JSON document:
184 json expected = R"(
192 CHECK(doc.patch(json::diff(doc, expected)) == expected);
197 // An example target JSON document:
198 json const doc = R"(
205 // A JSON Patch document:
206 json const patch = R"(
212 json expected = R"(
223 CHECK(doc.patch(json::diff(doc, expected)) == expected);
228 // An example target JSON document:
229 json const doc = R"(
241 // A JSON Patch document:
242 json const patch = R"(
248 // The resulting JSON document:
249 json expected = R"(
265 CHECK(doc.patch(json::diff(doc, expected)) == expected);
270 // An example target JSON document:
271 json const doc = R"(
275 // A JSON Patch document:
276 json const patch = R"(
282 // The resulting JSON document:
283 json expected = R"(
291 CHECK(doc.patch(json::diff(doc, expected)) == expected);
296 // An example target JSON document:
297 json doc = R"(
304 // A JSON Patch document that will result in successful evaluation:
305 json const patch = R"(
320 // An example target JSON document:
321 json const doc = R"(
325 // A JSON Patch document that will result in an error condition:
326 json patch = R"(
333 CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
335 …CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: "…
337 …CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + pa…
343 // An example target JSON document:
344 json const doc = R"(
348 // A JSON Patch document:
349 json const patch = R"(
355 // The resulting JSON document:
356 json expected = R"(
370 CHECK(doc.patch(json::diff(doc, expected)) == expected);
375 // An example target JSON document:
376 json const doc = R"(
380 // A JSON Patch document:
381 json const patch = R"(
387 json expected = R"(
398 CHECK(doc.patch(json::diff(doc, expected)) == expected);
403 // An example target JSON document:
404 json const doc = R"(
408 // A JSON Patch document:
409 json const patch = R"(
415 // This JSON Patch document, applied to the target JSON document
421 …CHECK_THROWS_WITH_AS(doc.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", js…
424 // A.13. Invalid JSON Patch Document
429 // An example target JSON document:
430 json const doc = R"(
437 // A JSON Patch document:
438 json const patch = R"(
444 json expected = R"(
455 CHECK(doc.patch(json::diff(doc, expected)) == expected);
460 // An example target JSON document:
461 json const doc = R"(
468 // A JSON Patch document that will result in an error condition:
469 json patch = R"(
476 CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
478 …CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: "…
480 …CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + pa…
486 // An example target JSON document:
487 json const doc = R"(
491 // A JSON Patch document:
492 json const patch = R"(
498 // The resulting JSON document:
499 json expected = R"(
507 CHECK(doc.patch(json::diff(doc, expected)) == expected);
521 // An example target JSON document:
522 json const doc = 17;
524 // A JSON Patch document:
525 json const patch = R"(
531 // The resulting JSON document:
532 json expected = {1, 2, 3};
538 CHECK(doc.patch(json::diff(doc, expected)) == expected);
547 // An example target JSON document:
548 json const doc = {0, 1, 2};
550 // A JSON Patch document:
551 json const patch = R"(
557 // The resulting JSON document:
558 json expected = {0, 1, 2, 3};
564 CHECK(doc.patch(json::diff(doc, expected)) == expected);
570 // An example target JSON document:
571 json const doc = R"(
583 // A JSON Patch document:
584 json const patch = R"(
590 // The resulting JSON document:
591 json expected = R"(
608 CHECK(doc.patch(json::diff(doc, expected)) == expected);
613 json const j = "string";
614 json const patch = {{{"op", "replace"}, {"path", ""}, {"value", 1}}};
615 CHECK(j.patch(patch) == json(1));
621 // a JSON patch
622 json const p1 = R"(
626 // a JSON value
627 json const source = R"(
632 json target = source.patch(p1);
637json p2 = json::diff(target, source); // NOLINT(readability-suspicious-call-argument)
642 // a JSON value
643 json j = {"good", "bad", "ugly"};
645 // a JSON pointer
646 auto ptr = json::json_pointer("/2");
656 json flat = j.flatten();
668 json const j;
669 json const patch = {{"op", "add"}, {"path", ""}, {"value", 1}};
670 …ROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an …
675 json const j;
676 json const patch = {"op", "add", "path", "", "value", 1};
678 …WS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: (/0) JSON patch must be …
680 …ROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an …
686 json const j;
687 json const patch = {{{"foo", "bar"}}};
689 …HROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must h…
691 …K_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must hav…
697 json const j;
698 json const patch = {{{"op", 1}}};
700 …WS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have…
702 …ROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must have st…
708 json const j;
709 json const patch = {{{"op", "foo"}, {"path", ""}}};
711 …HROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation value …
713 …_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation value 'fo…
722 json const j;
723 json const patch = {{{"op", "add"}}};
725 …S_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must…
727 …ROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must h…
733 json const j;
734 json const patch = {{{"op", "add"}, {"path", 1}}};
736 …ITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must ha…
738 …_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have …
744 json const j;
745 json const patch = {{{"op", "add"}, {"path", ""}}};
747 …S_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must…
749 …OWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must ha…
755 json const j = {1, 2};
756 json const patch = {{{"op", "add"}, {"path", "/4"}, {"value", 4}}};
757 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 4 is out of ra…
765 json const j;
766 json const patch = {{{"op", "remove"}}};
768 …_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' mu…
770 …WS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must …
776 json const j;
777 json const patch = {{{"op", "remove"}, {"path", 1}}};
779 …H_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must h…
781 …WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must hav…
787 json const j = {1, 2, 3};
788 json const patch = {{{"op", "remove"}, {"path", "/17"}}};
789 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 17 is out of r…
794 json const j = {{"foo", 1}, {"bar", 2}};
795 json const patch = {{{"op", "remove"}, {"path", "/baz"}}};
796 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json
801 json const j = "string";
802 json const patch = {{{"op", "remove"}, {"path", ""}}};
803 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.405] JSON pointer has no parent…
811 json const j;
812 json const patch = {{{"op", "replace"}}};
814 …WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' mu…
816 …WS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must…
822 json const j;
823 json const patch = {{{"op", "replace"}, {"path", 1}}};
825 …H_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must …
827 …ITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must hav…
833 json const j;
834 json const patch = {{{"op", "replace"}, {"path", ""}}};
836 …WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' mu…
838 …S_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must …
844 json const j = {1, 2, 3};
845 json const patch = {{{"op", "replace"}, {"path", "/17"}, {"value", 19}}};
846 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 17 is out of r…
851 json const j = {{"foo", 1}, {"bar", 2}};
852 json const patch = {{{"op", "replace"}, {"path", "/baz"}, {"value", 3}}};
853 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json
861 json const j;
862 json const patch = {{{"op", "move"}}};
864 …S_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' mus…
866 …OWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must h…
872 json const j;
873 json const patch = {{{"op", "move"}, {"path", 1}}};
875 …TH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must ha…
877 …_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have…
883 json const j;
884 json const patch = {{{"op", "move"}, {"path", ""}}};
885 CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
887 …S_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' mus…
889 …OWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must h…
895 json const j;
896 json const patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}};
897 CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
899 …TH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must ha…
901 …_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have…
907 json const j = {1, 2, 3};
908 json const patch = {{{"op", "move"}, {"path", "/0"}, {"from", "/5"}}};
909 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 5 is out of ra…
914 json const j = {{"foo", 1}, {"bar", 2}};
915 json const patch = {{{"op", "move"}, {"path", "/baz"}, {"from", "/baz"}}};
916 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json
924 json const j;
925 json const patch = {{{"op", "copy"}}};
927 …S_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' mus…
929 …OWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must h…
935 json const j;
936 json const patch = {{{"op", "copy"}, {"path", 1}}};
938 …TH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must ha…
940 …_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have…
946 json const j;
947 json const patch = {{{"op", "copy"}, {"path", ""}}};
949 …S_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' mus…
951 …OWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must h…
957 json const j;
958 json const patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
960 …TH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must ha…
962 …_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have…
968 json const j = {1, 2, 3};
969 json const patch = {{{"op", "copy"}, {"path", "/0"}, {"from", "/5"}}};
970 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 5 is out of ra…
975 json const j = {{"foo", 1}, {"bar", 2}};
976 json const patch = {{{"op", "copy"}, {"path", "/fob"}, {"from", "/baz"}}};
977 …CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json
985 json const j;
986 json const patch = {{{"op", "test"}}};
988 …S_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' mus…
990 …OWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must h…
996 json const j;
997 json const patch = {{{"op", "test"}, {"path", 1}}};
999 …TH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must ha…
1001 …_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have…
1007 json const j;
1008 json const patch = {{{"op", "test"}, {"path", ""}}};
1010 …_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must…
1012 …OWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must h…
1023 json const doc = R"(
1031 json const patch = R"(
1040 json result = R"(
1051 CHECK(doc.patch(json::diff(doc, result)) == result);
1057 json const doc = R"(
1069 json const patch = R"(
1076 json result = R"(
1090 CHECK(doc.patch(json::diff(doc, result)) == result);
1096 json const patch = R"(
1103 json result = R"(
1111 CHECK(doc.patch(json::diff(doc, result)) == result);
1117 json const patch = R"(
1124 json result = R"(
1137 CHECK(doc.patch(json::diff(doc, result)) == result);
1143 json const patch = R"(
1150 json result = R"(
1166 CHECK(doc.patch(json::diff(doc, result)) == result);
1172 json const patch = R"(
1179 json result = R"(
1192 CHECK(doc.patch(json::diff(doc, result)) == result);
1198 json patch = R"(
1205 CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
1207 …CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: "…
1209 …CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + pa…
1283 SECTION("Tests from github.com/json-patch/json-patch-tests")
1287 TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json",
1288 TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"
1293 json const suite = json::parse(f);