title: Using json key to store value, is it a good approach?
body: <p>I am writing a rest api and I am quite new to the json serialization.</p>
  
  <p>I know that a json object consists of pairs of <code>&lt;key&gt;:&lt;value&gt;</code>.</p>
  
  <p>I have an object "channels" which contains multiple channel objects which consist of an id and some other attributes like "x", "y" and "z".</p>
  
  <p>In our team we found two ways to represent the object "channels", the usual way that I see people implement is like this:</p>
  
  <pre><code>{
  "channels":
      [
          {
              "id":0,
              "x":0,
              "y":0,
              "z":0
          },
          ...
      ]
  }
  </code></pre>
  
  <p>There is also this version, which uses the id as key:</p>
  
  <pre><code>{
  "channels":
      {
          "0":
          {
              "x":0,
              "y":0,
              "z":0
          },
          ...
      }
  }
  </code></pre>
  
  <p>Please note that the first implementation explicitily uses an array while the second relies on the <code>&lt;key&gt;</code> to access the specific channel directly.</p>
  
  <p>What is the best way to represent this object? Is it ok to represent a key as value (like the id of the previous case)?</p>
  
  <p>Right now there are only two channels (always with id 0 and 1), but in the future we may add more.</p>