Skip to content

questions regarding from_json #1226

Description

@tamarlev

I have a problem where if I try to convert json to a class, and the class have std::optional members I need to always check if the keys exists in the json and only if they exists (in json) then I can capture their data, something like:
m_id = (j.find("ID") != j.end() && j.at("ID") != nullptr)? j.at("ID").getstd::string() : nullopt;
how can I avoid it?
is there a way to change 'get' j.at("ID").getstd::string() and return either nullopt and avoid asking if 'ID' exists and not nullptr?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions