Changeset View
Changeset View
Standalone View
Standalone View
src/base/json-utils.hpp
| Show All 30 Lines | inline bool isNonCompoundCanonicalJsonValue(const nlohmann::json &j) | ||||
| || j.is_boolean() | || j.is_boolean() | ||||
| || j.is_null(); | || j.is_null(); | ||||
| } | } | ||||
| template<class Jsonish, class RangeT> | template<class Jsonish, class RangeT> | ||||
| std::optional<std::decay_t<Jsonish>> getInJson(Jsonish &&j, RangeT &&path, std::size_t index = 0) | std::optional<std::decay_t<Jsonish>> getInJson(Jsonish &&j, RangeT &&path, std::size_t index = 0) | ||||
| { | { | ||||
| if (index >= path.size()) { | if (index >= path.size()) { | ||||
| return std::forward<Jsonish>(j); | return std::optional<std::decay_t<Jsonish>>(std::forward<Jsonish>(j)); | ||||
| } | } | ||||
| auto currentSegment = path[index]; | auto currentSegment = path[index]; | ||||
| if (j.is_object() && j.contains(currentSegment)) { | if (j.is_object() && j.contains(currentSegment)) { | ||||
| return getInJson(std::forward<Jsonish>(j)[currentSegment], std::forward<RangeT>(path), index + 1); | return getInJson(std::forward<Jsonish>(j)[currentSegment], std::forward<RangeT>(path), index + 1); | ||||
| } | } | ||||
| return std::nullopt; | return std::nullopt; | ||||
| } | } | ||||
| } | } | ||||