Jonas
Jonas

Reputation: 7945

Ignore a Key with JSON encode

How can I ignore a key when using json.encode?

Something like this:

final map = json.decode(json.encode(routine), reviver: (key, value) {
      if (key == "id") {
        return null;
      }
      return value;
    });

But this way my map has a key id with value null. I want my map to not have the id key.

Any Idea?

Upvotes: 2

Views: 1278

Answers (1)

janstol
janstol

Reputation: 3156

You can remove the key.

routine.remove("id");
final map = json.decode(json.encode(routine));

Upvotes: 1

Related Questions