Skip to content
Discussion options

You must be logged in to vote

<discarded> is an internal JSON value used by the parser callback mechanism. It is not valid JSON syntax, so a dumped value containing it should not be fed back into json::parse().

If the goal is "remove all object members whose value is null", I would not rely on filtering the value event directly. It is easier and more predictable to parse normally, then erase null members recursively:

#include <nlohmann/json.hpp>

using json = nlohmann::json;

void erase_null_object_members(json& j)
{
    if (j.is_object()) {
        for (auto it = j.begin(); it != j.end(); ) {
            if (it->is_null()) {
                it = j.erase(it);
            } else {
                erase_null_object_members

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nlohmann
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