title: How to iterate a json object if it has combination of string,boolean and number type
body: <p>I had a <code>node.js</code> app where it takes JSON object and then it encrypts the JSON object key value. I had a function which takes value and then encrypts data. Now I need to iterate only the JSON key value to the function which I'm able to do using.</p>
  
  <pre><code>var JsonData = JSON.parse(jsonString);
  var callFunction = iterate(JsonData);
  
  function iterate(JsonData) {
      for (var exKey in JsonData) {
          if (JsonData.hasOwnProperty(exKey)) {
              if (typeof JsonData[exKey] == "object") {
                  iterate(JsonData[exKey]);
              } else {
                  JsonData[exKey] = encrypt(JsonData[exKey]);
              }
          }
      }
  }
  var encrpted = JSON.stringify(JsonData);
  </code></pre>
  
  <p>But the problem is I'm able to iterate only the string type JSON object.i.e., (ex <code>{"name":"sam","gender":"male"}</code>). If we are having JSON object with <code>boolean</code> or number or both type along with string type,it is not able to iterate and I'm getting some error..(ex. <code>{"name":"sam","age":21,"isMarried":false}</code>).</p>
  
  <p>So how can I iterate through that function if I have other than string type? I know that using replace function we can convert <code>boolean</code>, num type to string and then pass to function.But since I'm doing encryption and then decryption, here after decrypted we get everything in string type, which I don't want.They need to be in their original type.So I think this will not work. So can anyone suggest any ideas and help me. Hope my question is clear. Any suggestions appreciated.</p>