Update toJson to replace from ref