I have a JArray from a json-file like this:
[
{
"pos": 36,
"name": "name1",
"id": 1
},
{
"pos": 36,
"name": "name2",
"id": 2
},
{
"pos": 36,
"name": "name2",
"id": 3
}
]
And I need save json back with unique elements filtered by set of fields. The set of fields can be any.
Update In real file I have 3000 elements in the JArray and about 20 fields. I have no idea how to solve this problem.
Example 1 If I filter the JArray by name I expect to get
[
{
"pos": 36,
"name": "name1",
"id": 1
},
{
"pos": 36,
"name": "name2",
"id": 2
}
]
Example 2 If I filter the JArray by "name" and "pos" I expect to get
[
{
"pos": 36,
"name": "name1",
"id": 1
}
]
2
Answers
It was easy :). Maybe someone knows how to pack it in one linq?
You can filter with this code without serializing(with Newtonsoft.Json.Linq;)
first find unique element and then Serialize to json(Newtonsoft.Json)
If you want to group several, I realized something from your example, you can write this code
Result
If you want to group only once(Really distinct ), use this code
Result:
Base Code: