Skip to content

How to initialise single object from map and key-value pair? #3611

Discussion options

You must be logged in to vote

I don't think that's currently possible but shouldn't be too difficult to add.
However, you can do the following:

    std::map<std::string, int> amap{{"a key", 0}};
    json j{{"some other key", 1}};
    j.update(json(amap));

(Note that json(amap) and json{amap} produce different results!)

See https://json.nlohmann.me/api/basic_json/update/ for details.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fixgoats
Comment options

Answer selected by fixgoats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants