I have a structure similar to this (only test data, so typos are irrelevant):
"People" : [
{
"name": "Bob",
"animals" : [{
"name" : "Scott",
"type" : "Cat"
},
{
"name" : "Eva",
"type" : "Cat"
}
{
"name" : "Sven",
"type" : "Dog"
}]
},
{
"name": "Bob",
"animals" : [{
"name" : "Chris",
"type" : "Dog"
},
{
"name" : "Greg",
"type" : "Cat"
},
{
"name" : "Ior",
"type" : "Horse"
}]
}
]
Basically what I want to do is to get all unique animal types from this collection. My problem is mapping into two arrays (People : [], Animals : []
). The question:
How do I .map all the "type" attributes to get a new unique collection? like:
["Cat", "Dog", "Horse"]
Will update if I get an example done using C# LINQ.