title: Unity3d: How to store Dictionary as object in JSON?
body: <p>I'm new to the Unity3d and C#. I want to store some data in JSON files, so they are <strong>easy to edit in text editor</strong>.</p>
  
  <p>So far I used JsonUtility because its build in Unity, and it worked great. Possibility to use it as easy as:</p>
  
  <pre><code>string json = JsonUtility.ToJson(foo);
  Foo foo = JsonUtility.FromJson&lt;Foo&gt;(json);
  </code></pre>
  
  <p>was great for me.</p>
  
  <p>But now, I added some Dictionaries. They are later converted for more afficient data structures, but I want to serialize them to JSON as named objects.</p>
  
  <p>Here is sample of my code. The Objects structure in my case is set and known. Single Dictionary keeps one type of objects, and Dictionary is set deeper in hierarchy of serializable objects.</p>
  
  <pre><code>[System.Serializable]
  public struct Bar{
      public int x;
      public int y;
  }
  
  [System.Serializable]
  public class Foo{
      public int otherData = 43;
      public Dictionary&lt;string,Bar&gt; bar = new Dictionary&lt;string,Bar&gt;(){
          {"spaceship", new Bar{x = 7, y = 11}},
          {"pirates", new Bar{x = 5, y = -3}},
      };
  }
  </code></pre>
  
  <p>What I want to achieve:</p>
  
  <pre><code>{
     "otherData": 43,
     "bar": {
          "spaceship": {"x": 7, "y": 11},
          "pirates": {"x": 5, "y": -3}
     }
  }
  </code></pre>
  
  <p>Is it any way to make that work?</p>
  
  <p>Maybe is a way that I can write my on serialization/deserialization methods for Dictionary?</p>