title: Composing a simple JSON response in Java
body: <p>Imagine a simple JSON response such as:</p>
  
  <pre><code>{
      "success": false,
      "message": "PEBKAC"
  }
  </code></pre>
  
  <p>Given I have <code>boolean</code> and <code>String</code> variables, what's the simplest way to convert them to JSON in Java, without resorting to <code>String.format</code> and friends.</p>
  
  <p>I'm more familiar with C#, where this is quite straightforward using the built-in <a href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx" rel="noreferrer"><code>JavaScriptSerializer</code> class</a>:</p>
  
  <pre><code>var success = false;
  var message = "PEBKAC";
  var serializer = new JavaScriptSerializer();
  var json = serializer.Serialize(new { success, message });
  </code></pre>
  
  <p>Is there anything this straightforward for Java?</p>