title: pg nodejs package results in 'invalid input syntax for type json'
body: <p>I have following setup for my project, using the <a href="https://www.npmjs.com/package/pg" rel="nofollow noreferrer">pg</a> node-postgres package:</p>
  
  <p><a href="https://i.stack.imgur.com/aoYA5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aoYA5.png" alt="enter image description here"></a></p>
  
  <p>The simple table 'tmp' looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/B0LBo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B0LBo.png" alt="enter image description here"></a></p>
  
  <p>According to <a href="http://json.org/" rel="nofollow noreferrer">jsonORG</a> and the <a href="https://www.postgresql.org/docs/9.6/static/datatype-json.html" rel="nofollow noreferrer">postgres docs</a> the object:</p>
  
  <pre><code>{"foo" : true}
  </code></pre>
  
  <p>is syntactically valid JSON, and when using the pgAdmin Query-tool with:  </p>
  
  <pre><code>UPDATE tmp SET data = '{"foo": false}' WHERE id = '1'
  </code></pre>
  
  <p>works fine, but when i try updating my table through my express route using pg:</p>
  
  <pre><code>router.put('/updateTMP', (req, res) =&gt; {
      // I use dummies in this case instead of req.body.someKey for testing purposes
      let dummyJSON = {"foo":true};
      let dummyID = 1;
      pg.query(`UPDATE tmp SET data = '${dummyJSON}' WHERE id = '${dummyID}'`, (errUpdate, responseUpdate) =&gt; {
          if (!errUpdate) { // NO ERROR
              res.json({success: true, message: responseUpdate});
          }
          else { // ERROR
              console.log(dummyJSON);
              console.log(errUpdate);
              res.json({success: false, message: errUpdate}); 
          }
      })
  })
  </code></pre>
  
  <p>I get the following error from the database:</p>
  
  <pre><code>error: invalid input syntax for type json
  </code></pre>
  
  <p>I've tried the <a href="https://www.postgresql.org/docs/9.6/static/functions-json.html" rel="nofollow noreferrer">to_json</a> function from postgresql and the <a href="https://www.npmjs.com/package/to-json" rel="nofollow noreferrer">to-json package</a> from npm in the express route - all with the same negative result.</p>
  
  <p>Am i missing some fundamental understanding or is it some formating/quoting-issue?</p>
  
  <p>Thanks in advance for your ideas! ;)</p>
  
  <p>ps: And yes - I've read through <a href="https://stackoverflow.com/questions/31873723/inserting-json-in-to-postgresql-how-to-avoid-unescaped-characters">this</a>, and <a href="https://stackoverflow.com/questions/45971754/preventing-invalid-input-syntax-for-type-json-in-postgres">that</a> article..</p>