fixed toJSON to recursively create a JS object + cut/copy/paste functionality