TypeError: Cannot read property 'toJSON' of null