Lines Matching refs:json

4 // |_____|_____|_____|_|___|  https://github.com/nlohmann/json
11 #include <nlohmann/json.hpp>
12 using nlohmann::json;
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;
38 json patch1 = R"([{ "op": "add", "path": "/a/b", "value": [ "foo", "bar" ] }])"_json;
44 json doc1 = R"({ "a": { "foo": 1 } })"_json;
60 json doc2 = R"({ "q": { "bar": 2 } })"_json;
63 CHECK_THROWS_WITH_AS(doc2.patch(patch1), "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&);
65 json doc3 = R"({ "a": {} })"_json;
66 json 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", json::out_of_range&);
72 CHECK_THROWS_WITH_AS(doc3.patch(patch2), "[json.exception.out_of_range.403] key 'b' not found", json::out_of_range&);
80 json doc = {1, 2, 3, 4};
81 json patch = {{{"op", "remove"}, {"path", "/1"}}};
82 CHECK(doc.patch(patch) == json({1, 3, 4}));
88 json doc = R"(
93 json patch = R"(
100 json expected = R"(
111 CHECK(doc.patch(json::diff(doc, expected)) == expected);
117 json doc = R"(
122 json patch = R"(
129 json expected = R"(
137 CHECK(doc.patch(json::diff(doc, expected)) == expected);
143 json doc = R"(
151 json patch = R"(
158 json expected = R"(
166 CHECK(doc.patch(json::diff(doc, expected)) == expected);
172 json doc = R"(
177 json patch = R"(
184 json expected = R"(
192 CHECK(doc.patch(json::diff(doc, expected)) == expected);
198 json doc = R"(
206 json patch = R"(
212 json expected = R"(
223 CHECK(doc.patch(json::diff(doc, expected)) == expected);
229 json doc = R"(
242 json patch = R"(
249 json expected = R"(
265 CHECK(doc.patch(json::diff(doc, expected)) == expected);
271 json doc = R"(
276 json patch = R"(
283 json expected = R"(
291 CHECK(doc.patch(json::diff(doc, expected)) == expected);
297 json doc = R"(
305 json patch = R"(
321 json doc = R"(
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: " + patch[0].dump());
337 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
344 json doc = R"(
349 json patch = R"(
356 json expected = R"(
370 CHECK(doc.patch(json::diff(doc, expected)) == expected);
376 json doc = R"(
381 json patch = R"(
387 json expected = R"(
398 CHECK(doc.patch(json::diff(doc, expected)) == expected);
404 json doc = R"(
409 json patch = R"(
421 CHECK_THROWS_WITH_AS(doc.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
430 json doc = R"(
438 json patch = R"(
444 json expected = R"(
455 CHECK(doc.patch(json::diff(doc, expected)) == expected);
461 json doc = R"(
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: " + patch[0].dump());
480 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
487 json doc = R"(
492 json patch = R"(
499 json expected = R"(
507 CHECK(doc.patch(json::diff(doc, expected)) == expected);
522 json doc = 17;
525 json patch = R"(
532 json expected = {1, 2, 3};
538 CHECK(doc.patch(json::diff(doc, expected)) == expected);
548 json doc = {0, 1, 2};
551 json patch = R"(
558 json expected = {0, 1, 2, 3};
564 CHECK(doc.patch(json::diff(doc, expected)) == expected);
571 json doc = R"(
584 json patch = R"(
591 json expected = R"(
608 CHECK(doc.patch(json::diff(doc, expected)) == expected);
613 json j = "string";
614 json patch = {{{"op", "replace"}, {"path", ""}, {"value", 1}}};
615 CHECK(j.patch(patch) == json(1));
622 json p1 = R"(
627 json source = R"(
632 json target = source.patch(p1);
637 json p2 = json::diff(target, source); // NOLINT(readability-suspicious-call-argument)
643 json j = {"good", "bad", "ugly"};
646 auto ptr = json::json_pointer("/2");
656 json flat = j.flatten();
668 json j;
669 json patch = {{"op", "add"}, {"path", ""}, {"value", 1}};
670 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects", json::parse_error&);
675 json j;
676 json patch = {"op", "add", "path", "", "value", 1};
678 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects", json::parse_error&);
680 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects", json::parse_error&);
686 json j;
687 json patch = {{{"foo", "bar"}}};
689 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have member 'op'", json::parse_error&);
691 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must have member 'op'", json::parse_error&);
697 json j;
698 json patch = {{{"op", 1}}};
700 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'", json::parse_error&);
702 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must have string member 'op'", json::parse_error&);
708 json j;
709 json patch = {{{"op", "foo"}, {"path", ""}}};
711 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation value 'foo' is invalid", json::parse_error&);
713 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation value 'foo' is invalid", json::parse_error&);
722 json j;
723 json patch = {{{"op", "add"}}};
725 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'", json::parse_error&);
727 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have member 'path'", json::parse_error&);
733 json j;
734 json patch = {{{"op", "add"}, {"path", 1}}};
736 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'", json::parse_error&);
738 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have string member 'path'", json::parse_error&);
744 json j;
745 json patch = {{{"op", "add"}, {"path", ""}}};
747 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'", json::parse_error&);
749 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have member 'value'", json::parse_error&);
755 json j = {1, 2};
756 json 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 range", json::out_of_range&);
765 json j;
766 json patch = {{{"op", "remove"}}};
768 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'", json::parse_error&);
770 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must have member 'path'", json::parse_error&);
776 json j;
777 json patch = {{{"op", "remove"}, {"path", 1}}};
779 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'", json::parse_error&);
781 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must have string member 'path'", json::parse_error&);
787 json j = {1, 2, 3};
788 json 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 range", json::out_of_range&);
794 json j = {{"foo", 1}, {"bar", 2}};
795 json patch = {{{"op", "remove"}, {"path", "/baz"}}};
796 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
801 json j = "string";
802 json patch = {{{"op", "remove"}, {"path", ""}}};
803 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
811 json j;
812 json patch = {{{"op", "replace"}}};
814 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'", json::parse_error&);
816 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have member 'path'", json::parse_error&);
822 json j;
823 json patch = {{{"op", "replace"}, {"path", 1}}};
825 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'", json::parse_error&);
827 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have string member 'path'", json::parse_error&);
833 json j;
834 json patch = {{{"op", "replace"}, {"path", ""}}};
836 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'", json::parse_error&);
838 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have member 'value'", json::parse_error&);
844 json j = {1, 2, 3};
845 json 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 range", json::out_of_range&);
851 json j = {{"foo", 1}, {"bar", 2}};
852 json 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::out_of_range&);
861 json j;
862 json patch = {{{"op", "move"}}};
864 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'", json::parse_error&);
866 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have member 'path'", json::parse_error&);
872 json j;
873 json patch = {{{"op", "move"}, {"path", 1}}};
875 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'", json::parse_error&);
877 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have string member 'path'", json::parse_error&);
883 json j;
884 json patch = {{{"op", "move"}, {"path", ""}}};
885 CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
887 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'from'", json::parse_error&);
889 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have member 'from'", json::parse_error&);
895 json j;
896 json patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}};
897 CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
899 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'from'", json::parse_error&);
901 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have string member 'from'", json::parse_error&);
907 json j = {1, 2, 3};
908 json 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 range", json::out_of_range&);
914 json j = {{"foo", 1}, {"bar", 2}};
915 json 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::out_of_range&);
924 json j;
925 json patch = {{{"op", "copy"}}};
927 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'", json::parse_error&);
929 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have member 'path'", json::parse_error&);
935 json j;
936 json patch = {{{"op", "copy"}, {"path", 1}}};
938 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'", json::parse_error&);
940 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'path'", json::parse_error&);
946 json j;
947 json patch = {{{"op", "copy"}, {"path", ""}}};
949 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'", json::parse_error&);
951 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have member 'from'", json::parse_error&);
957 json j;
958 json patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
960 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'", json::parse_error&);
962 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'from'", json::parse_error&);
968 json j = {1, 2, 3};
969 json 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 range", json::out_of_range&);
975 json j = {{"foo", 1}, {"bar", 2}};
976 json 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::out_of_range&);
985 json j;
986 json patch = {{{"op", "test"}}};
988 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'", json::parse_error&);
990 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have member 'path'", json::parse_error&);
996 json j;
997 json patch = {{{"op", "test"}, {"path", 1}}};
999 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'", json::parse_error&);
1001 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have string member 'path'", json::parse_error&);
1007 json j;
1008 json patch = {{{"op", "test"}, {"path", ""}}};
1010 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'", json::parse_error&);
1012 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have member 'value'", json::parse_error&);
1023 json doc = R"(
1031 json patch = R"(
1040 json result = R"(
1051 CHECK(doc.patch(json::diff(doc, result)) == result);
1057 json doc = R"(
1069 json patch = R"(
1076 json result = R"(
1090 CHECK(doc.patch(json::diff(doc, result)) == result);
1096 json patch = R"(
1103 json result = R"(
1111 CHECK(doc.patch(json::diff(doc, result)) == result);
1117 json patch = R"(
1124 json result = R"(
1137 CHECK(doc.patch(json::diff(doc, result)) == result);
1143 json patch = R"(
1150 json result = R"(
1166 CHECK(doc.patch(json::diff(doc, result)) == result);
1172 json 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: " + patch[0].dump());
1209 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
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 suite = json::parse(f);