title: MySQL query returns a string as a result of JSON_OBJECT()
body: <p>I wrote a query that gives me posts from a table and also returns an info about each post's author:</p>
  
  <pre><code>SELECT post.id, post.text, post.datetime, JSON_OBJECT(
                  'username', user.username,
                  'firstName', user.firstName,
                  'firstName', user.lastName) as author
                  FROM post
                  INNER JOIN user ON post.authorId = user.id;
  </code></pre>
  
  <p>But in response the <code>author</code> field is a string:</p>
  
  <pre><code>author: "{"username": "@", "firstName": null}"
  datetime: "2017-05-02T20:23:23.000Z"
  id: 10
  text: "5555"
  </code></pre>
  
  <p>I tried to fix that using <code>CAST</code> but anyway <code>author</code> is a string:</p>
  
  <pre><code>CAST(JSON_OBJECT(
      'username', user.username,
      'firstName', user.firstName,
      'firstName', user.lastName) as JSON) as author
  </code></pre>
  
  <p>Why is it happened and how to fix that?</p>
  
  <p>UPD:</p>
  
  <p>I send the data from server using Node.js and Express:</p>
  
  <pre><code>app.get('/posts', (req, res, next) =&gt; {
      getPosts().then((posts) =&gt; {
          res.setHeader('Content-Type', 'application/json');
          res.send(posts);
      })
      .catch(next);
  });
  
     // ...
  
  getPosts() {
          return new Promise((resolve, reject) =&gt; {
              const query = `
              SELECT post.id, post.text, post.datetime, JSON_OBJECT(
                  'username', user.username,
                  'firstName', user.firstName,
                  'firstName', user.lastName) as author
                  FROM post
                  INNER JOIN user ON post.authorId = user.id;`;
              this.connection.query(query, (err, result) =&gt; {
                  if(err) {
                      return reject(new Error("An error occured getting the posts: " + err));
                  }
  
                  console.log(result) // prints author as a string 
  
                  resolve(result || []);
              });
          });
      }
  </code></pre>
  
  <p>Result of <code>console.log</code>:</p>
  
  <pre><code>{
      id: 1,
      text: 'hello, world!',
      datetime: 2017-05-02T15:08:34.000Z,
      author: '{"username": "@", "firstName": null}' 
  }
  </code></pre>
  
  <p>I also tried here change <code>res.send(posts)</code> to <code>res.json(posts)</code> but it's doesn't help.</p>
  
  <p>My function from client that touch server for the posts:</p>
  
  <pre><code>export const getPosts = () =&gt; {
      customFetch(apiUrl + '/posts')
      .then(response =&gt; response.json())
      .then(json =&gt; json)
  };
  </code></pre>