Deleting all keys that have null values

Try this:

DeleteCases[test, "", {2}]

{<|"A" -> 1, "B" -> 2|>, <|"A" -> 3, "B" -> 4, "C" -> 5|>, <|"B" -> 6, "C" -> 7|>}

Since this is about a list of associations, the level on which to search the pattern "" is level 2 (only), therefore the {2} as third argument.


Select:

Select[# != "" &] /@ test

{<|"A" -> 1, "B" -> 2|>, <|"A" -> 3, "B" -> 4, "C" -> 5|>, <|"B" -> 6,    "C" -> 7|>}

DeleteMissing:

DeleteMissing[test /. "" -> Missing[], 2]

{<|"A" -> 1, "B" -> 2|>, <|"A" -> 3, "B" -> 4, "C" -> 5|>, <| "B" -> 6,   "C" -> 7|>}

AssociationMap:

AssociationMap[If[#[[2]] == "", Nothing, #] &] /@ test

{<|"A" -> 1, "B" -> 2|>, <|"A" -> 3, "B" -> 4, "C" -> 5|>, <| "B" -> 6, "C" -> 7|>}

Tags:

Associations