I have 10,000 JSON files which contain attributes, some of which are marked as Empty.
Attributes that must stay look like this:
{"trait_type":"Skin","value":"Euphoria"}, whilst attributes that must be removed look like this {"trait_type":"Tattoo","value":"Empty"},
These empty attributes appear multiple times in some JSON files, while sometimes none in others.
Here is my code, however I must apologise is it seems that i've barely tried, but I've deleted most of it now out of frustration.
using System.Web;
using System.Text.Encodings.Web;
internal class Program
{
private static void Main(string[] args)
{
var jsonPath = @"/Users/jasonnienaber/Desktop/nft/cef/official/fatJSONselfFIX/test/test2";
var jsonFiles = Directory.GetFiles(jsonPath, "*.json").OrderBy(f => f);
string toRemove = "Empty";
foreach(var jsonFile in jsonFiles)
{
var json = File.ReadAllText(jsonFile);
var sample = JsonSerializer.Deserialize<Sample>(json);
if (json.Contains(toRemove))
{
}
}
}
public class Attribute
{
public string trait_type { get; set; }
public string value { get; set; }
}
public class Sample
{
public string image { get; set; }
public string name { get; set; }
public string description { get; set; }
public string external_url { get; set; }
public List<Attribute> attributes { get; set; }
public string compiler { get; set; }
}
}
I'm also aware that I have not re-sereliazed yet, and i'll need to delete the old file and write to a new file. I'm new to C# and just need assistance deleting the aforementioned Empty attributes.