Export json data of selected objects

I’d like to export json data of selected parts only.
How can I do this?
Model.toJson() exports whole diagram.
But I’d like to export only selected parts.

It is probably easiest to create a temporary unseen Diagram, call Diagram.copyParts of the main Diagram.selection to the temporary diagram, and then call Model.toJson on the temporary diagram’s model.