'C# Newtonsoft.JSON serialize/deserialize array of objects

I'm unsure how to go about serializing/deserializing an array of objects which implement an interface using Newtonsoft.JSON. Here's a basic example:

public interface IAnimal {
  public int NumLegs { get; set; }
  //etc..
}

public class Cat : IAnimal {...}
public class Dog : IAnimal {...}
public class Rabbit : IAnimal {...}

public IAnimal[] Animals = new IAnimal[3] {
  new Cat(),
  new Dog(),
  new Rabbit()
}

How would I go about serializing/deserializing the Animals array?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source