Add toJSON function.