Skip to content

How to add json to another json? #1718

Description

@TrueWodzu

Hi,

I am struggling a little when trying to add one json to another. Let me explain:

FramePickingResult PickFrame(int current_frame_number)
{
	if (current_frame_number > frames.back())
		return FramePickingResult::Abort;
	if (current_frame_number == frames[frame_index])
	{
		++frame_index;
		return FramePickingResult::Pick;
	}
	else
		return FramePickingResult::Skip;
}

std::optional<nlohmann::json> B()
{
	nlohmann::json result;
	result["B"] = {
		{ "SomeOtherObject", 34578}
	};
	return result;
};

std::optional<nlohmann::json> C()
{
	nlohmann::json result;
	result["C"] = {
		{ "Name", "Mark"}
	};
	return result;
};


int main(int argc, char* argv[])
{
	nlohmann::json json;
	json["Profiles"] = {};
	if (auto json_b = B())
	{
		// Add this to "Profiles"
	}

	if (auto json_c = C())
	{
		// Add this to "Profiles"
	}
}

{ "Profiles" : { "B" : { "SomeOtherObject: : 34578 }, "C" : { "Name" : "Mark" } } }

How can I achieve that? I would like to avoid using initializer list, thanks.
EDIT: To be honest I don't even know how to construct this with initializer list ;)

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