title: How to receive (and decode) JSON from post data in Node.Js Express?
body: <p>Suppose I have sent data with the following code:</p>
  
  <pre><code>        $.ajax({
              type: "POST",
              url: "/save/" + #{key},
              data: transitions2,
              success: function (data) {
  
              },
              dataType: "json"
          });
  </code></pre>
  
  <p>where <code>transitions2</code> is hierarchical JS object.</p>
  
  <p>Now how can I receive it intact at server side</p>
  
  <pre><code>router.post('/save/:key', function(req, res) {
      // where is my data here?    
  });
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I found info about body parsers, and found that my site template already contained them. Particularly, <code>app.js</code> contains:</p>
  
  <pre><code>...
  var bodyParser = require('body-parser');
  ...
  // uncomment after placing your favicon in /public
  //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  app.use('/data', express.static(path.join(__dirname, '../data')));
  
  app.use('/', index);
  ...
  </code></pre>
  
  <p>So I wrote in my <code>index.js</code>:</p>
  
  <pre><code>...
  router.post('/save/:key', function(req, res) {
      var transitions = req.body;
      image_data.save_transitions(req.params.key, req.query.postfix, transitions);
  });
  ...
  </code></pre>
  
  <p>Unfortunately, <code>transitions</code> contains</p>
  
  <p><a href="https://i.stack.imgur.com/ydPGa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ydPGa.png" alt="enter image description here"></a></p>
  
  <p>while on client side it contained</p>
  
  <p><a href="https://i.stack.imgur.com/NFLgm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NFLgm.png" alt="enter image description here"></a></p>
  
  <p>i.e. was full of data.</p>
  
  <p>What can be the problem?</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I tried to do</p>
  
  <pre><code>        $.ajax({
              type: "POST",
              url: "/save/" + #{key},
              data: JSON.stringify(transitions2),
              success: function (data) {
  
              }
          });
  </code></pre>
  
  <p>and I see in <code>Fiddler2</code> now, that full Json is passed. </p>
  
  <pre><code>[{"start_image":"20170402_1_NATURAL_COL0R","end_image":"20170409_1_NATURAL_COL0R","transition_classes":["no_transition","some_activity"]},...
  </code></pre>
  
  <p>Unfortunately, on server side I observe truncated and corrupted string </p>
  
  <p><a href="https://i.stack.imgur.com/DmE6W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DmE6W.png" alt="enter image description here"></a></p>
  
  <p>(equal sign should not be in JSON). </p>
  
  <p>And JSON.parse fails.</p>