Skip to content

Instantly share code, notes, and snippets.

@lfgrando
Created August 21, 2018 15:54
Show Gist options
  • Save lfgrando/c8d27fbb3f06f13b40f4cf13b5f0eb69 to your computer and use it in GitHub Desktop.
Save lfgrando/c8d27fbb3f06f13b40f4cf13b5f0eb69 to your computer and use it in GitHub Desktop.
How to rename a JToken
private void RenameToken(JToken token, string newName)
{
var parent = token.Parent;
if (parent == null)
throw new InvalidOperationException("The parent is missing.");
var newToken = new JProperty(newName, token);
parent.Replace(newToken);
}
JToken cpf = serializedCustomer["documents"]?["cpf"];
if (cpf != null)
RenameToken(cpf, "Cpf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment