Created
July 27, 2022 11:43
-
-
Save dancojocaru2000/4e582cc081e17c2560d6445998183be4 to your computer and use it in GitHub Desktop.
Check keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final json = [ | |
{ | |
"name": "to", | |
"type": "address", | |
}, | |
{ | |
"name": "tokenId", | |
"type": "uint256", | |
}, | |
]; | |
void main() { | |
final toCheck = { | |
"to": "1", | |
"tokenId": 1, | |
}; | |
final keysNotInToCheck = json.map((v) => v["name"]).where((k) => !toCheck.keys.contains(k)).toList(); | |
if (keysNotInToCheck.isNotEmpty) { | |
print('Keys missing in toCheck: ${keysNotInToCheck.join(', ')}'); | |
} | |
else { | |
print('All good!'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment