You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
625 B

  1. #include <json.hpp>
  2. using json = nlohmann::json;
  3. int main()
  4. {
  5. // create a JSON value
  6. json j =
  7. {
  8. {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
  9. };
  10. // read-only access
  11. // output element with JSON pointer "/number"
  12. std::cout << j.at("/number"_json_pointer) << '\n';
  13. // output element with JSON pointer "/string"
  14. std::cout << j.at("/string"_json_pointer) << '\n';
  15. // output element with JSON pointer "/array"
  16. std::cout << j.at("/array"_json_pointer) << '\n';
  17. // output element with JSON pointer "/array/1"
  18. std::cout << j.at("/array/1"_json_pointer) << '\n';
  19. }