toJSON() should support maxNesting param too.