title: How can I use Underscore.js to transform/obfuscate each value in an object
body: <p>I'm trying to use Underscore.js to step through an object and transform/obfuscate each value, so that:</p>
  
  <pre><code>{
    "weather": "Cloudy",
    "degrees": 90
  }
  </code></pre>
  
  <p>becomes:</p>
  
  <pre><code>{
    "weather": "Claido",
    "degrees": 21
  }
  </code></pre>
  
  <p>The completely incomprehensible reason- I'm trying to obfuscate JSON objects without ruining their structure. So if it's string, I replace any vowel with another random vowel. If it's a digit, I just pick another random digit, booleans are set randomly, and so on. I can build each element type manipulation, I'm just now sure how to recursively do it.</p>
  
  <p>I can do something like this:</p>
  
  <pre><code>var t = { "weather":"Cloudy", "degrees": 12, "snowing": false };
  var newObj = {};
  var g = _.each(t, function(value, key, list) {
    if (_.isString(value)){
       newObj[key] = value.replace(/[aeiou]/gi, '');
    }
    if (_.isNumber(value)){
       var n = Math.floor((Math.random()*10)+1);
       newObj[key] = n + value;
    }
    if (_.isBoolean(value)){
      newObj[key] = Math.random() &gt;= 0.5;
    }
  });
  console.log(newObj);
  </code></pre>
  
  <p>And all is well. The problem is with arrays and nested objects like so:</p>
  
  <pre><code>{
   "weather": "Cloudy",
   "outsideWeather": {
       "forecast": "Stormy",
       "outside": 48
   },
   "degrees": 12,
   "snowing": false
  }
  </code></pre>
  
  <p>My simple Switch cases break down at that point. Any ideas how to recursively step through each value, transform it, then build the object back to it's original structure?</p>
  
  <p>Many thanks</p>