title: recursively flatten a nested jsonb in postgres without unknown depth and unknown key fields
body: <p>How can I recursively flatten a nested jsonb in postgres which I don't know the depth and the field at each depth? (see example below)</p>
  
  <p>A postgressql query to do the flattening would be much apreciated</p>
  
  <pre><code>    {
         "xx": "",
         "xx": "",
         "form": "xxx",
         "type": "",
         "content_type": "xxx",
         "reported_date": ,
         "contact": {
             "imported_date": "",
             "name": "",
             "phone": "",
             "alternate_phone": "",
             "specialization": "",
             "type": "",
             "reported_date": ,
             "parent": {
                 "_id": "xxx",
                 "_rev": "xxx",
                 "parent": "",
                 "type": "xxx" 
                 } 
          }
      }
  </code></pre>
  
  <p>I have searched in stack overflow but they only consider jsonb's which have a single depth and the keys are already known before</p>