Add more _templated_ JsonUtils #3574

Open
opened 2026-01-30 23:24:43 +00:00 by claunia · 0 comments
Owner

Originally created by @zadjii-msft on GitHub (Aug 26, 2019).

Originally assigned to: @DHowett on GitHub.

In #2515 I started adding some really useful JsonUtils that let us get a property from a json object if it exists.

Unfortunately, I made them like this:


    void GetOptionalColor(const Json::Value& json,
                          std::string_view key,
                          std::optional<uint32_t>& target);

    void GetOptionalString(const Json::Value& json,
                           std::string_view key,
                           std::optional<std::wstring>& target);

    void GetOptionalGuid(const Json::Value& json,
                         std::string_view key,
                         std::optional<GUID>& target);

    void GetOptionalDouble(const Json::Value& json,
                           std::string_view key,

They really should have all been template specializations of GetOptionalValue, but I didn't want to burn a day trying to fight compiler errors.

Furthermore, we should probably also just have JsonUtils::GetValue<typename T>() that does the same thing, but w/o the optional<T>'s.

Originally created by @zadjii-msft on GitHub (Aug 26, 2019). Originally assigned to: @DHowett on GitHub. In #2515 I started adding some really useful `JsonUtils` that let us get a property from a json object if it exists. Unfortunately, I made them like this: ```c++ void GetOptionalColor(const Json::Value& json, std::string_view key, std::optional<uint32_t>& target); void GetOptionalString(const Json::Value& json, std::string_view key, std::optional<std::wstring>& target); void GetOptionalGuid(const Json::Value& json, std::string_view key, std::optional<GUID>& target); void GetOptionalDouble(const Json::Value& json, std::string_view key, ``` They really should have all been template specializations of `GetOptionalValue`, but I didn't want to burn a day trying to fight compiler errors. Furthermore, we should probably also just have `JsonUtils::GetValue<typename T>()` that does the same thing, but w/o the `optional<T>`'s.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#3574