Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to convert an "uninitialized" json into an empty object or empty array #1456

Closed
ibc opened this issue Jan 25, 2019 · 1 comment
Closed

Comments

@ibc
Copy link

ibc commented Jan 25, 2019

I've a function that receives a json reference as follows:

void Parameters::FillJson(json& object) const
{
  // It iterates internal stuff here to add key/values into the given
  // object
}

and it's called from outside as follows:

parameters.FillJson(root["parameters"]);

where root is the parent json object. So root["parameters"] is created in place. If FillJson() above does not add any key to the given object, when printing root["parameters"] it outputs null.

So, how could I force object within FillJson() to be an empty object? I couldn't find any API for it.

@ibc
Copy link
Author

ibc commented Jan 25, 2019

Oh, forget it. It's just about doing:

void Parameters::FillJson(json& object) const
{
  // For it to be an object even if no key/values are added.
  object = jon::object();

  // It iterates internal stuff here to add key/values into the given
  // object
}

@ibc ibc closed this as completed Jan 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant