title: Designing data structure
body: <p>I'm writing a hobby web application. It currently sends JSON objects to the client, which in turn creates them into blog posts. Currently the JSON object looks like this:</p>
  
  <pre><code>{"id1": {"title": "title1", "content": "content1", ...}, "id2": {...}, ...}
  </code></pre>
  
  <p>Sometimes order starts to matter. For example if i want to create a random order of display for the blog posts. Currently i use a separate array <code>post_ids</code>, which looks like <code>["id1", "id2", ...]</code>, and its values are used as keys for the JSON object above.</p>
  
  <p>Obviously, my object could look as the following:</p>
  
  <pre><code>[{"id": "id1", "title": "title1", "content": "content1"}, ...]
  </code></pre>
  
  <p>But then i would lose the ability to index by ID and would need to traverse my data every time.</p>
  
  <p>Sometimes i also have an object and i want to get its ID. I could include ID into the initial object:</p>
  
  <pre><code>{"id1": {"id": "id1", "title": "title1", ...}, ...}
  </code></pre>
  
  <p>What is the canonical way to design a data structure, that contains these CouchDB/MongoDB style documents?</p>