|
nlohmann::json | ghassanpl::formats::json::load_file (std::filesystem::path const &from, std::error_code &ec) |
|
nlohmann::json | ghassanpl::formats::json::try_load_file (std::filesystem::path const &from, nlohmann::json const &or_json=empty_json) |
|
nlohmann::json | ghassanpl::formats::json::load_file (std::filesystem::path const &from) |
|
void | ghassanpl::formats::json::save_file (std::filesystem::path const &to, nlohmann::json const &j, bool pretty=true) |
|
nlohmann::json const & | ghassanpl::formats::json::get (nlohmann::json const &g, std::string_view key, jtype type=jtype::discarded) |
| Gets the item in the json object g with the key key , or an empty json object if none found.
|
|
std::string | ghassanpl::formats::json::get (nlohmann::json const &g, std::string_view key, std::string_view default_value, jtype type=jtype::discarded) |
| Gets the value (converted to a string) in the json object g with the key key , or default_value if none found.
|
|
template<std::integral T> |
T | ghassanpl::formats::json::get (nlohmann::json const &g, std::string_view key, T default_value, jtype type=jtype::discarded) |
| Gets the value (converted to an integer) in the json object g with the key key , or default_value if none found.
|
|
nlohmann::json const & | ghassanpl::formats::json::get_array (nlohmann::json const &g, std::string_view key) |
| Gets the array value in the json object g with the key key , or an empty array if none found.
|
|
template<typename T > |
void | ghassanpl::formats::json::field (T &val, nlohmann::json const &g, std::string_view key) |
| Sets the value of val to the item in json object g with key key
|
|
template<typename T > |
void | ghassanpl::formats::json::field (T &val, nlohmann::json const &g, size_t key) |
| Sets the value of val to the item in json array g at index key
|
|
template<typename T > |
bool | ghassanpl::formats::json::field_opt (T &val, nlohmann::json const &g, std::string_view key) |
| Same as field() but returns if it succeeded, instead of throwing.
|
|
template<typename VISIT_FUNC > |
auto | ghassanpl::formats::json::visit (nlohmann::json const &j, VISIT_FUNC &&func) |
| Calls func with the actual value inside j ; similar to std::visit
|
|
constexpr const char * | ghassanpl::formats::json::type_name (nlohmann::json::value_t type) noexcept |
|
template<std::integral T>
T ghassanpl::formats::json::get |
( |
nlohmann::json const & |
g, |
|
|
std::string_view |
key, |
|
|
T |
default_value, |
|
|
jtype |
type = jtype::discarded |
|
) |
| |
|
inline |
Gets the value (converted to an integer) in the json object g
with the key key
, or default_value
if none found.
Gets the value (converted to an floating point number) in the json object g
with the key key
, or default_value
if none found.
- Parameters
-
type | the value must also be of this type |
Definition at line 210 of file json_helpers.h.