Use .toJSON when stringifying

fixes #299 with regression test