title: Postgresql view with json output
body: <p>I'd like to set up a postgres view which outputs its results as json.</p>
  
  <p>The view should query a table called events:</p>
  
  <pre><code>CREATE OR REPLACE VIEW jsonview AS 
  SELECT array_to_json(array_agg(t)) as events_as_json
  FROM (SELECT * FROM events)t
  </code></pre>
  
  <p>and give results in a json. This works but I now, I'd like to specify the output of the view with something like this:</p>
  
  <pre><code>SELECT * FROM jsonview
  WHERE events.year_begin = 1552;
  </code></pre>
  
  <p>But this produces an error due to non existing entry.
  Any suggestions?</p>