title: Converting a JSON object's fields into Title Case
body: <p>I have a JSON object I get from a database (using Slim and Twig) but there's a field that is sometimes in upper case, sometimes in lower case, sometimes in camelCase, etc. I'd like that this field becomes TitleCase.</p>
  
  <p>I already have a function to convert a String to TitleCase, which I have used when converting JSON to arrays (using these arrays as sources for jqWidgets) :</p>
  
  <pre><code>function toTitleCase(str) {
      return str.replace(/\w\S*/g, function (txt) {return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
  }
  </code></pre>
  
  <p>Now I'd like to do the same thing for JSON objects. What I thought of is to iterate over them after using parseJSON(), use my function on the fields I want and return new objects after using JSON.stringify(); but I'm wondering if you think this is the best approach to this problem or if you have a better idea (I'm not asking for direct source code).</p>
  
  <p>Example of my JSON (I need nomFonction and nomEntite in TitleCase) :</p>
  
  <pre><code>"[{"idFonction":"1","nomFonction":"Manager","nomEntite":"DIRECTION"},{"idFonction":"2","nomFonction":"Développeur","nomEntite":"SERVICE CONTROLE"},{"idFonction":"3","nomFonction":"Stagiaire","nomEntite":"SERVICE COMPTABILITE"},{"idFonction":"4","nomFonction":"rjeizjrze","nomEntite":"DIRECTION"}]"
  </code></pre>