Refactor function that makes NDB record JSON serializable