Use rootKey in toJSON if available