so I’m trying to read yaml files and store them in json in a database, so I can do some bulk querying of them. Trouble is – I can’t seem to be able to make a generic function that reads yaml files. I started with:
public static string ToJson(string yaml)
{
var deserializer = new DeserializerBuilder().Build();
var yamlObject = deserializer.Deserialize<object>(yaml);
return Json.Serialize(yamlObject);
}
but am getting things like “unresolved tag !master”. Now – this a whole bag of yaml files of different types from different sources – they could be using anything…
I tried this:
public static string ToJson(string yaml)
{
var deserializer = new DeserializerBuilder().IgnoreUnmatchedProperties()
.WithNodeDeserializer(inner => new IgnoreUnknownTagsDeserializer(inner),
s => s.InsteadOf<ObjectNodeDeserializer>()).Build();
var yamlObject = deserializer.Deserialize<object>(yaml);
return Json.Serialize(yamlObject);
}
with my own function to look for a tag name starting with ! – but my function doesn’t get called.
So currently I’m writing my own deserialization library from a base level parsing library – but it seems like I’m doing something wrong. Surely it’s possible to write a generic function that takes any yaml and turns it into json?? I know people can build custom tags and they can do things, but it’s very unlikely I’ll be querying them anyway – I just want to do anything with them so I can get a serialization of the rest of the yaml?