Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Print keys were values is null in map<String,dynamic> Employee in dart

This is the code json code from which I want to get all the keys were value is null

{
   "service": "register",
   "employee": {
       "employeeId": "bcvfevse",
       "officeId": null,
       "email": null,
       "name" : "Chetan Patil",
       "position" : "Flutter Developer",
       "number" : null
   },
   "device": {
       "type": "android",
       "uniqueId": "9774d56d682e549c"
   }
}

I Want something like this ["number","email","officeId"] in "DART"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you have something like this:

var json = {
   "service": "register",
   "employee": {
       "employeeId": "bcvfevse",
       "officeId": null,
       "email": null,
       "name" : "Chetan Patil",
       "position" : "Flutter Developer",
       "number" : null
   },
   "device": {
       "type": "android",
       "uniqueId": "9774d56d682e549c"
   }

And in Dart you do something like:

var nullEntries = (json['employee'] as Map<String, dynamic>).entries.where((e) => e.value == null).toList();

Then if you print it out like this:

print(nullEntries.map((p) => p.key));

You get:

(officeId, email, number)

Let me know if that’s what you’re looking for.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading