using System.Collections.Generic;
using System.Text.Json.Serialization;
[JsonPropertyName("offerId")]
public long OfferId { get; set; }
[JsonPropertyName("metadata")]
public Metadata Metadata { get; set; }
[JsonPropertyName("score")]
public double Score { get; set; }
[JsonPropertyName("algorithm")]
public string Algorithm { get; set; }
[JsonPropertyName("marker")]
public string Marker { get; set; }
[JsonPropertyName("additionalInfo")]
public AdditionalInfo AdditionalInfo { get; set; }
public class AdditionalInfo
[JsonPropertyName("algorithm")]
public string Algorithm { get; set; }
[JsonPropertyName("cluster")]
public string Cluster { get; set; }
[JsonPropertyName("displayOption")]
public string DisplayOption { get; set; }
[JsonPropertyName("seen")]
public string Seen { get; set; }
public static string GetClusterName(Offer offer) {
if(offer.Metadata.AdditionalInfo.Seen == "true") return "last";
return $"{offer.Metadata.AdditionalInfo.Algorithm}_{offer.Metadata.AdditionalInfo.Cluster}";
public static List<List<Offer>> SplitOffersIntoLists(List<Offer> offers)
var result = new List<List<Offer>>();
List<Offer> current = new List<Offer>();;
for(int i=0; i< offers.Count; i++){
if(GetClusterName(last) != GetClusterName(offers[i])){
current = new List<Offer>();
public static void Main()
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""displayOption"": ""nologo""
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""displayOption"": ""nologo""
""marker"": ""tname_214_tgroup_B_promoted"",
""marker"": ""tname_214_tgroup_B"",
""displayOption"": ""nologo""
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""displayOption"": ""nologo""
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B"",
""marker"": ""tname_214_tgroup_B_promoted"",
List<Offer> offers = JsonSerializer.Deserialize<List<Offer>>(json);
foreach (var sublist in SplitOffersIntoLists(offers))
Console.WriteLine("CLUSTER=================================");
foreach (var offer in sublist)
Console.WriteLine($" OfferId: {offer.OfferId}, Cluster: {offer.Metadata.AdditionalInfo.Cluster}, Algorithm: {offer.Metadata.AdditionalInfo.Algorithm}");