Categories
Programming Tips

Capitalizing the First Letter in All Keys of a JSON Object using C#

It took me some time to get this right, drawing from discussions on StackOverflow, but here is code that will capitalize the first letter of every key in a JSON object.

public static JObject Capitalize(JObject obj)
{
  JObject newObj = new JObject();
  foreach (var o in obj)
    {
      string key = o.Key;
      string newKey = char.ToUpper(key[0]) + key.Substring(1);
      JToken value = o.Value;
      if (value.HasValues)
      {
        try
        {
          JObject child = JObject.Parse(value.ToString());
          JObject newValue = Capitalize(child);
          value = newValue;
        }
        catch (Exception)
        {
        }
      }
      newObj[newKey] = value;
    }
  return newObj;
}
Categories
FTP

FTP Does Not Mix with VPN

Just posting this in case you run into this problem.  A couple of weeks ago, I was helping a customer troubleshoot her FTP connection to the hosting company that I work for.  After going through the standard troubleshooting checklist of performing trace route and telnet tests, shutting down antivirus and firewall hardware/software, and restarting the computer, I couldn’t figure out why it was connecting and then immediately terminating the connection.  When I tried it on my end, it worked fine.  It turns out the customer had an active VPN connection running, so once she turned it off, everything worked again.  So next time you’re having trouble, try turning off your VPN.