title: Binary Data in JSON String. Something better than Base64
body: <p>The <a href="http://www.json.org/" rel="noreferrer">JSON format</a> natively doesn't support binary data. The binary data has to be escaped so that it can be placed into a string element (i.e. zero or more Unicode chars in double quotes using backslash escapes) in JSON.</p>
  
  <p>An obvious method to escape binary data is to use Base64. However, Base64 has a high processing overhead. Also it expands 3 bytes into 4 characters which leads to an increased data size by around 33%.</p>
  
  <p>One use case for this is the v0.8 draft of the <a href="http://www.snia.org/tech_activities/publicreview" rel="noreferrer">CDMI cloud storage API specification</a>. You create data objects via a REST-Webservice using JSON, e.g.</p>
  
  <pre><code>PUT /MyContainer/BinaryObject HTTP/1.1
  Host: cloud.example.com
  Accept: application/vnd.org.snia.cdmi.dataobject+json
  Content-Type: application/vnd.org.snia.cdmi.dataobject+json
  X-CDMI-Specification-Version: 1.0
  {
      "mimetype" : "application/octet-stream",
      "metadata" : [ ],
      "value" :   "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
      IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
      dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
      dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
      ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",
  }
  </code></pre>
  
  <p>Are there better ways and standard methods to encode binary data into JSON strings?</p>