Skip to content

Make optional user-data available in from_json #864

@chadlayton

Description

@chadlayton

I'd like to be able to supply optional user-data to json::parse which would then be retrievable in from_json. A naive implementation might look like this:

void from_json(const json& j, image& img, void* user_data)
{
	const char* root_directory = reinterpret_cast<const char*>(user_data);
	std::string filename = j["filename"];

	img.data = load_external_dependency(std::string(root_directory) + "//" + filename);
}

// ...

json j = json::parse(json_string, "C:\\images\\");

Or maybe this is already possible? Right now the only way I can see to do it requires global state or caching the data on the object and fixing it up after parsing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: proposed fixa fix for the issue has been proposed and waits for confirmationsolution: wontfixthe issue will not be fixed (either it is impossible or deemed out of scope)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions