title: Javascript object encoding/decoding when passing a message to an API
body: <p>I am passing a message to a third party message queue which relays the message to my queue listener (all in node.js server side). The message has a predefined format which allows me to define "custom properties". This works fine when I provide basic types (string, number, etc) but when I try and pass an object in the custom properties, it fails. </p>
  
  <p>Sending this message:</p>
  
  <pre><code>var info = {foo: 100};
  var message = {
      body: 'some string',
      customProperties: {
          type: 1,
          name: 'test',
          info: info
      }
  };
  </code></pre>
  
  <p>Returns this message: </p>
  
  <pre><code>{
      body: 'some string',
      customProperties: {
          type: 1,
          name: 'test',
          info: '[object Object]' 
      }
  };
  </code></pre>
  
  <p>And sending this message:</p>
  
  <pre><code>var info = {foo: 100};
  var message = {
      body: 'some string',
      customProperties: {
          type: 1,
          name: 'test',
          info: JSON.stringify(info)
      }
  };
  </code></pre>
  
  <p>Returns this message:</p>
  
  <pre><code>{
      body: 'some string',
      customProperties: {
          type: 1,
          name: 'test',
          info: '\\"{\\"foo\\":100}\\"' 
      }
  };
  </code></pre>
  
  <p>Which then fails when I try to decode it with <code>JSON.parse(customProperties.info)</code>. I think what is happening is that it is calling <code>.toString</code> on each custom property? Any ideas how I can encode/decode a simple object when passing this message?</p>