title: Parsing functions stored as strings in object literal/JSON syntax and differetiating
body: <p>There is a previous question (<a href="https://stackoverflow.com/questions/11556131/parsing-a-json-like-string-that-contains-functions">here</a>), however the answers there does not answer my question exactly - the accepted answer contained invalid JSON (mandating the use of <code>eval()</code>), which is simply not possible to do even something like that as far as I am aware.</p>
  
  <p>I'm planning to use code from my own server that is stored as object literal syntax in a string, however I'd like the ability to store functions in there as well.</p>
  
  <p>Currently, I've thought of the following possibilities:</p>
  
  <ol>
  <li>Simply use <code>eval()</code> to parse the string</li>
  <li>Place functions in string form (with something like <code>"\bfunction"</code> to be able to identify them), running <code>JSON.parse()</code> on it and then use a for-in loop to see whether any such functions need to be parsed (probably quite slow)</li>
  <li>Use the DOM to run the code using a <code>&lt;script&gt;</code> tag and just run it there</li>
  </ol>
  
  <p>This code will not contain anything that's supposed to be user-editable, however I'm not sure whether there would still be a safety issue or just a speed one.  Would using <code>eval()</code> be appropriate for my situation, and is there a more effective method of doing this than parsing for functions manually or using <code>eval()</code>?</p>
  
  <p>EDIT: would an alternative syntax to parse be better or would that just make things even more complicated?</p>
  
  <p>EDIT2: I'm looking simply to do something like the following:</p>
  
  <pre><code>{ "test": function () {}
  , "foo": 1
  , "bar": 2 }
  </code></pre>
  
  <p>I'm <strong>not</strong> looking to just parse an entire function from a string, e.g.</p>
  
  <pre><code>eval('function(){}');
  </code></pre>