title: Access a single SQLAlchemy object through JS
body: <p>I am attempting to update most of my site data based on the selection in a select2 field by using on change. I have followed tutorials that use <code>fetch</code> to create a JSON file with information pulled from the database. Although, this scenario is slightly different because I am trying to access one object for use in my JS to update some site HTML. </p>
  
  <p>I have tried using <code>fetch</code> to return the object but I have found it returns an array with random data about the URL.</p>
  
  <h2>views.py</h2>
  
  <pre><code>@app.route('/selected_room/&lt;int:room_id&gt;')
  def selected_room(room_id):
      room = Room.query.filter_by(id=room_id).first_or_404()
  
      return room
  </code></pre>
  
  <h2>returns:</h2>
  
  <pre><code>body: (...)
  bodyUsed: false
  headers: Headers {}
  ok: true
  redirected: false
  status: 200
  statusText: "OK"
  type: "basic"
  url: "http://127.0.0.1:5000/room/2"
  </code></pre>
  
  <p>I've already posted some of this code above but here is everything I currently have set up.</p>
  
  <h2>views.py</h2>
  
  <pre><code>@app.route('/selected_room/&lt;int:room_id&gt;')
  def selected_room(room_id):
      room = Room.query.filter_by(id=room_id).first_or_404()
  
      return room
  </code></pre>
  
  <h2>js</h2>
  
  <pre><code>$(document).ready(function(){
      $('#rooms').on('change', function() {
          var room_id = $(this).val();
  
          fetch('/room/' + room_id).then(function(data) {
              // this console.log is me testing to see what data returns
              console.log(room_id, data, data.room_id, data.room, data.rooms);
          });
      });
  });
  </code></pre>
  
  <p>In reality, I am looking for the JS replacement of <code>{{ object.id(etc) }}</code>. Either I am totally off and this can't be done or I am simply on the wrong track. Thanks for the help!</p>