RocketPy
RocketPy copied to clipboard
ENH: make rocketpy classes json serializable
Is your feature request related to a problem? Please describe.
Exporting rocketpy classes to a json file is something that the user currently cannot do so easily.
The get_instance_attributes
(see below) function already made an important advance to export all the attributes of an instance to a dictionary, but that doesn't mean we can always save these dictionaries to json files.
Exporting objects as json files might be the easiest way of saving a rocketpy simulation without having to plot tons of data and plots.
https://github.com/RocketPy-Team/RocketPy/blob/14dd0f6bb263c82eb8f137847b0480288e500743/rocketpy/utilities.py#L642
Describe the solution you'd like
- Add
to_json
,to_serializable
or__json__
methods to the important classes of RocketPy, allowing the - Alternatively, the
jsonpickle
package can be used to perform a quick encode/decode with any of the rocketpy classes, as already done in the EnvironmentAnalysis class. https://github.com/RocketPy-Team/RocketPy/blob/14dd0f6bb263c82eb8f137847b0480288e500743/rocketpy/environment/environment_analysis.py#L2899
Additional context
As far as I know there's no convention on Python regarding the name of the method