| 51 | // back to its default without discarding any other valid field. |
| 52 | template <typename T> |
| 53 | T get_or(const nlohmann::json& j, const std::string& key, T def) { |
| 54 | if (!j.is_object() || !j.contains(key)) { |
| 55 | return def; |
| 56 | } |
| 57 | try { |
| 58 | return j.at(key).get<T>(); |
| 59 | } catch (const nlohmann::json::exception&) { |
| 60 | return def; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | } // namespace |
| 65 |
no outgoing calls
no test coverage detected