title: Create Simple Node.js API from JSON files
body: <p>I have a folder of JSON files that I'd like to use to create a simple API from. </p>
  
  <p>Here's a simplified version of my folder structure:</p>
  
  <p><code>/clients.json</code></p>
  
  <p><code>/clients/1/client.json</code></p>
  
  <p><code>/clients/2/client.json</code></p>
  
  <p><code>...</code></p>
  
  <p>my <code>/clients.json</code> file looks like this:</p>
  
  <pre><code>[
      {
          "id": 1,
          "name": "Jon Parker"
      },
      {
          "id": 2,
          "name": "Gareth Edwards"
      },
      ...
  ]
  </code></pre>
  
  <p>and my <code>/clients/1/client.json</code> file looks like this:</p>
  
  <pre><code>[
      {
          "date": "2014-09-12",
          "score": 40,
          ...
      },
      {
          "date": "2015-02-27",
          "score": 75,
          ...
      },  
      {
          "date": "2015-05-10",
          "score": 75,
          ...
      },
      {
          "date": "2016-08-27",
          "score": 60,
          ...
      }
  ]
  </code></pre>
  
  <p>The id from <code>clients.json</code> relates to the folder in which the associated details are.</p>
  
  <p>I have a lot of JSON files in the clients folder and rather than loading these all individually on the client side, I wanted to create an API using Node.js that gives me more flexibility, i.e...</p>
  
  <p>returning a list of client names and id's
  <code>/clients</code></p>
  
  <p>returning the client details
  <code>/clients/:id/details</code></p>
  
  <p>and most importantly returning all clients with there names and associated details
  <code>/clients/all/details</code></p>
  
  <p>I did begin playing with <a href="https://github.com/typicode/json-server" rel="noreferrer">json-server</a>, however it requires that your JSON be an object rather than an array, and I'm stuck with the format of this JSON unfortunately.</p>
  
  <p>Appreciate any help!</p>