Fixed bug in toJSON where nested properties were not being correctly handled.