How to convert YAML to JSON?

Michael Brown picture Michael Brown · May 21, 2015 · Viewed 11.7k times · Source

I'm looking to convert between a YAML file, and JSON. This was really difficult to find any information on.

Answer

Antoine Aubry picture Antoine Aubry · May 22, 2015

If you do not need the features of Json.NET, you can also use the Serializer class directly to emit JSON:

// now convert the object to JSON. Simple!
var js = new Serializer(SerializationOptions.JsonCompatible);

var w = new StringWriter();
js.Serialize(w, o);
string jsonText = w.ToString();

You can check two working fiddles here: