Add support for serializing to JSON #193
Labels
code improvement
A feature request that will improve the software and its maintainability, but be invisible to users.
feature request
An issue that improves the user interface.
Due to the time it takes to read a model into MontePy, it is helpful for users to be able to serialize the model and write it to file to make loading in the future easier. Pickling is possible, but does come with a huge security vulnerability when sharing files. Instead a way to support serialization that does not allow code execution is needed. So JSON should be supported.
Some thoughts:
default
function that is passed to the load/dump function. This doesn't seem the cleanest as it would be nice for JSON to call a dunder function that an object implements sojson.dump
can just be called on an object.to_json
method, and sometimes afrom_json
.{"cell": {"number": {"value": 120, "token": "0120"} ...}
{"cell": {"number": 120, "mass_density": 10.0, importance: {"n": 1.0...}}}
How to implement:
MCNP_Problem.export_to_json()
for creating a JSON formatted Input FileMCNP_Problem.to_json()
for serializing the object state to json.MCNP_Problem.serialize
that will just generate a dictionary that can then be saved however the user wants.montepy.from_json
.The text was updated successfully, but these errors were encountered: