Skip to content

Ambiguity in parsing nested maps #840

@quicknir

Description

@quicknir

This is considered ambiguous and a compile time error:

#include "json.hpp"

#include <iostream>
#include <unordered_map>

using json = nlohmann::json;

int main()
{
    std::cerr << "foo";
    try {
        auto j = json::parse(R"(
                         { "m": {"one": int}}
                         )");

        using T = std::unordered_map<std::string, std::unordered_map<std::string, int>>;

         auto m = j.at("m").get<T>();
    }
    catch (...) {}
    return 0;
}

The error is a bit long but I can paste it here if desired. I don't see why this is ambiguous, seems like given the input and the types I specified there is only one possible output. Is this considered a bug? Either way, is there a workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: proposed fixa fix for the issue has been proposed and waits for confirmation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions