title: Storing and sending raw file data within a JSON object
body: <p>I'm looking for a way to transfer the raw file data of any file-type with any possible content (By that I mean files and file-content are all user generated) both ways using xhr/ajax calls in a Backbone front-end against a Django back-end.</p>
  
  <hr>
  
  <p>EDIT: Maybe the question is still unclear...</p>
  
  <p>If you open a file in an IDE (such as Sublime), you can view and edit the actual code that comprises that file. I'm trying to put <em>THAT</em> raw content into a JSON so I can send to the browser, it can be modified, and then sent back.</p>
  
  <p>I posted this question because I was under the impression that <strong>because the contents of these files can effectively be in ANY coding language</strong> that just stringify-ing the contents and sending it <em>seems</em> like a brittle solution that would be easy to break or exploit. Content could contain any number of <code>'</code>, <code>"</code>, <code>{</code> and <code>}</code> chars that would seem to break JSON formatting, and escaping those characters would leave artifacts within the code that would effectively break them (wouldn't it?).</p>
  
  <p>If that assumption is wrong, THAT would also be an acceptable answer (so long as you could point out whatever it is I'm overlooking).</p>
  
  <hr>
  
  <p>The project I'm working on is a browser-based IDE that will receive a complete file-structure from the server. Users can add/remove files, edit the content of those files, then save their changes back to the server. The sending/receiving all has to be handled via ajax/xhr calls.</p>
  
  <ul>
  <li>Within Backbone, each "file" is instantiated as a model and stored in a Collection. The contents of the file would be stored as an attribute on the model.</li>
  <li>Ideally, file content would still reliably throw all the appropriate events when changes are made.</li>
  <li>Fetching contents should not be broken out into a separate call from the rest of the file model. I'd like to just use a single save/fetch call for sending/receiving files including the raw content.</li>
  </ul>
  
  <p>Solutions that require Underscore/jQuery are fine, and I am able to bring in additional libraries if there is something available that specializes in managing that raw file data.</p>